This question already has an answer here:

I have a directory in my home-directory, which I share with a UNIX-group, but now want to delete.

If there is a file owned by an other user in this directory, I can remove it with rm, because the directory is owned by me. Not so with sub-directories, which are owned by other users. I can not delete them with rm -rf or rmdir.

me@unix:~/blub.git$ ll
total 3
drwxrwxr-x 5 me collab 5 Nov 30 13:32 objects
me@unix:~/blub.git$ cd objects/ && ll
total 8
drwx------ 2 bob collab 3 Nov 30 13:31 bb
drwx------ 2 bob collab 3 Nov 30 13:31 cf
drwx------ 2 bob collab 3 Nov 30 13:32 e6
me@unix:~/blub.git/objects$ rm -rf bb
rm: cannot remove `bb': Permission denied

How do I get rid of this shared folder anyway? Without help from root or the other user?

Or to ask the question in an other way: How can I really rmdir a not-empty directory without having to recursively rm -rf all the stuff in it?



To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty sub-directories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.

Is this really true?

marked as duplicate by Kevin Panko, Tog, Heptite, Dave M, Moses Jan 30 '14 at 20:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com Nov 30 '12 at 15:02

This question came from our site for professional and enthusiast programmers.

  • Not a programming question – Evert Nov 30 '12 at 13:27
  • Maybe your shared folder is simply yet shared? I mean, some process still using it. Try lsof for it, maybe it tells you the real reason – Andrew D. Nov 30 '12 at 13:45

Either get the users who own the subdirectories to allow you to write to them:

chmod -R 777 directoryname

...after which you'll be able to delete them.

Or have someone with root access help you out.

  • I was looking for a solution I could execute by myself. Thanks, anymay. I specified my question. – user1866407 Nov 30 '12 at 17:08
  • Ask your administrator if your system has a "forcefully delete something I own that has contents I don't own" function. Some systems do, some don't. If yours does, you'll never need to ask again. If yours doesn't, presumably there's a reason. If you want to know what it is, ask your system administrator. – David Schwartz Apr 19 '13 at 3:28

Seems like its possible only by root, or using extended file attributes (see discussion here).

Though, it's a bit surprisingly :)

  • Thanks. But I have no sticky-bits set. I added an example for clarifying that. – user1866407 Nov 30 '12 at 17:26

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