9

I cannot delete a folder as it says write only protected.Though I am using from root It says that I am not a root user. As I am new in using Ubuntu. Please help me to get rid of this problem.

2
  • 3
    Could you post the command you are using? Did you try with sudo?
    – migrc
    May 11, 2016 at 6:36
  • 1
    What are the exact steps and the output of ls -l /directory, lsattr /directory and mount
    – Braiam
    May 11, 2016 at 14:24

1 Answer 1

23

From the terminal you can run:

sudo rm -r /my/locked/directory

as the instruction will prompt any warning message during the execution and you will be able to check what are you deleting. Otherwise, if you have checked the warning and are completely sure of files and subfolders contained, you can run:

sudo rm -rf /my/locked/directory

This will remove recursively (-r) your folder, subfolders and any contents without prompt any warning (-f) .


If you receive the message: rm: cannot remove '/my/locked/directory': operation not permitted, then make sure directory (or file) is not protected using extended file system i attribute.

A file/folder with the i attribute cannot be modified, it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only root can add or remove i attribute.

Use lsattr command to verify that file/folder is not write protected using extended i attribute - output should be:

----i-------- /my/locked/directory

To remove the i attribute you can run:

sudo chattr -i /my/locked/directory

then check again with lsattr. The i should have been removed. If removed run the sudo rm -r instructions above.

7
  • 1
    In the rm statement I would also add the -v option to see which folders/files have been deleted.
    – efthialex
    May 11, 2016 at 13:21
  • 1
    Why do you want to use the -r?!?!
    – Braiam
    May 11, 2016 at 14:23
  • 1
    to recursive remove the entire directory and all its contents, including subdirectories May 11, 2016 at 14:30
  • I know, but why would you want to do this on a directory which you know nothing about?
    – Braiam
    May 11, 2016 at 15:08
  • 1
    Also, the filesystem might be mounted read-only, or the medium might not support write operations in the first place (e.g. a CD-ROM or a write-protected flash drive). May 11, 2016 at 15:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.