Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This seems very strange to me. I'm running kernel 2.6.37.2 and ran:

~]$ cp -r /proc/ here
~]$ rm -rf here

I get some permission denies when copying as expected and I eventually hit Control-C. I get Permission denied on a lot of files when trying to remove the new directory and files.

As a note, I found this weird behavior because a friend sent me a .tgz of a snapshot of his /proc dir. I extracted the directory and when I was finished looking through it I had the same problem.

rm -rf as root does work.

lsattr shows the e attribute (which is what all of my files/directories show).

EDIT: Oh wow, I can't believe I didn't notice. The directories had no write permission on them o.o

share|improve this question
    
I've generalized the title of your question a little because the core issue isn't about /proc. By the way, it's a bit late for this time, but if you figure out the answer after posting the question, it's fine to answer it yourself, and leave it up for other people who might run into a similar problem. –  Gilles Mar 2 '11 at 23:55
add comment

1 Answer

up vote 10 down vote accepted

If there is a non-empty directory where you don't have write permission, you can't remove its contents.

$ mkdir foo
$ touch foo/bar
$ chmod a-w foo
$ rm -rf foo
rm: cannot remove `foo/bar': Permission denied

The reason is that rm is bound by permissions like any other command, and permission to remove bar requires write permission on foo. This doesn't apply when you run rm as root because root always has the permission to remove a file.

To make the directory tree deletable, make all the directories in it writable (the permissions of regular files don't matter when it comes to deletion with rm -f). You can use either of these commands:

chmod -R u+w here        # slow if you have a lot of regular files
find here -type d -exec chmod u+w {} +
share|improve this answer
    
Heh, thanks again Gilles. I'm still newish with Unix/Linux system administration. I appreciate the help :) –  kisplit Mar 2 '11 at 22:49
add comment

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.