I have created a directory /home/web/test on a Debian server using a basic unprivileged account web. Another account — tomcat — then created some subdirectories and files in that folder (as you might have guessed, tomcat is a web application).

I would like to delete that test folder now, but I can't be because tomcat owns directories and files under it. I get Permission Denied errors when I try. Here's how it's set up:

ls -l /home/web

drwxrwxrwx 3 web users 4096 2011-04-19 12:06 test

ls -l /home/web/test

drwxr-xr-x 46 tomcat tomcat 4096 2011-04-19 12:06 www

ls -l /home/web/test/www

-rw-r--r-- 1 tomcat tomcat  9939 2011-04-19 12:44 test1.html
-rw-r--r-- 1 tomcat tomcat 16346 2011-04-19 12:44 test2.html

rm -rf /home/web/test

rm: cannot remove `/home/web/test/www/test1.html': Permission denied
rm: cannot remove `/home/web/test/www/test2.html': Permission denied

Is there any way that I can delete the /home/web/test folder using the web account — ie without logging in as tomcat or root?

After all, I own /home/web/test, shouldn't I be able to do anything I want with it?


You can't, as far as I can tell. You gave the tomcat user your permission to store their files on your directory, but their files are theirs. You can't modify or delete the files if you're not their owner or a member of their group (and you're not using extended ACLs).

Their location on the filesystem is pretty much irrelevant anyway as the same inode can be referenced multiple times on multiple locations. It's just not the way Unix permissions work - they are inode-based, not location-based.

EDIT: That's an interesting observation @syserr0r. The reason for this is that you, as the owner of a directory, can make changes to its file list - including deleting a file from that list (If the file has no hard links left then the operating system deletes the inode). So my answer is not correct: for creation and deletion the permissions that matter are the ones of the parent directory, not the ones associated to the inode.

  • +1 for mentioning inode... reading up on inodes explained a lot to me. I'm used to NTFS where ACLs inherit nicely down the directory tree, the inode approach is very different. – gutch Apr 20 '11 at 6:28

Single Folder

~/test with drwxr-xr-x owned by gompels group gompels
~/test/test0r with -rw-r--r-- owned by root group root

gompels@stonewall:~$rm -Rf test and the dirt folder is gone!

Nested Folder

~/test with drwxr-xr-x owned by gompels group gompels
~/test/test2/ with drwxr-xr-x owned by root group root
~/test/test2/test0r with -rw-r--r-- owned by root group root

gompels@stonewall:~$rm -Rf test and rm: cannot remove 'test/test2/test0r': Permission denied fail :(

So if you own the folder you can delete other peoples files in it, but not their folders.

  • Interesting... and I was surprised that it isn't all-or-nothing: I would have expected that either you can always delete the folder or you never can delete it; that you might be able to was unexpected. But after reading about inodes I think it makes more sense why it behaves so unnaturally. – gutch Apr 20 '11 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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