Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've couple of files that I cannot remove using rf -Rf command. I'm the owner of those file and the group assigned to those files is also a group my user is in. What's even weirder is that I can edit their content and I can change the permissions for them, but I can't move or delete them.

ls -al
total 12
dr-xr-xr-x 3 rayell pg1083760 4096 2010-10-10 10:00 .
drwxr-xr-x 3 rayell pg1083760 4096 2011-09-02 04:33 ..
-rwxrwxrwx 1 rayell pg1083760    0 2011-09-02 06:38 default.settings.php
drwxrwxrwx 2 rayell pg1083760 4096 2011-09-02 04:33 files
-rwxrwxrwx 1 rayell pg1083760    0 2011-09-02 06:38 settings.php


rm -Rf *
rm: cannot remove `default.settings.php': Permission denied
rm: cannot remove directory `files': Permission denied
rm: cannot remove `settings.php': Permission denied

Can anyone tell me what is happening?

share|improve this question
2  
In general, consider using rm -rf DIRECTORY_NAME and not "*". It will save you from that one time when you will think yourself in directory /some/where/safe but are instead in /home –  Sardathrion Sep 2 '11 at 15:56
    
Actually I did try that, it was just those 3 files that I couldn't remove so I have simplified to procedure a bit for this post's purpose. –  RaYell Sep 3 '11 at 6:17
    
Don't forget the lsattr and chattr command... –  user307335 Mar 13 at 5:36

2 Answers 2

up vote 25 down vote accepted

To remove one file you need write permission on the directory that contains¹ this file.

Here the permissions are dr-xr-xr-x 3 rayell pg1083760 4096 2010-10-10 10:00 . So nobody (other than root) can remove files inside this directory. The owner must use chmod first.


1. There are pretty good reasons for that. By ‘removing’ a file with rm, you are in fact trying to unlink it from the directory (hardlinked copies will not be deleted).

share|improve this answer
    
That worked, thanks. –  RaYell Sep 2 '11 at 14:19

The reason is that the parent directory has chmod 705 or something like that. You can chmod the parent directory by the following command:

chmod -R 777 directory_name

After this, you can remove that directory and the files it contains.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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