3

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?

Edit:

Wikipedia:

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?

2
  • Not a programming question
    – Evert
    Nov 30, 2012 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, 2012 at 13:45

2 Answers 2

1

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.

2
  • I was looking for a solution I could execute by myself. Thanks, anymay. I specified my question. Nov 30, 2012 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. Apr 19, 2013 at 3:28
0

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

Though, it's a bit surprisingly :)

1
  • Thanks. But I have no sticky-bits set. I added an example for clarifying that. Nov 30, 2012 at 17:26

Not the answer you're looking for? Browse other questions tagged .