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.
1 Answer
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.
-
1In the
rm
statement I would also add the-v
option to see which folders/files have been deleted. May 11, 2016 at 13:21 -
1
-
1to 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?– BraiamMay 11, 2016 at 15:08
-
1Also, 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
sudo
?ls -l /directory
,lsattr /directory
andmount