10

I created a directory somewhere with permissions rwxrwxr-x so that other users in my group can create files and directories in it.

I do need to be able to delete the contents in this "public" directory, but it seems that while I am able to remove any files in this directory I cannot remove and subdirectories under it.

Is there a way to remove such subdirectories owned by others under a directory owned by me?

3 Answers3

13

Deleting a file (or empty directory) requires write access to the parent directory, which you have as owner.
Deleting a non-empty directory requires that you empty the directory first, which you can't do, as you don't have write access to that directory (as it was created by other users).

So you need to use sudo to get root access to delete those directories.

  • 7
    I think this points out a missing tool -- there should be some program, setuid root, that allows someone to recursively remove any directory in a directory they own. (Which should prompt for confirmation by default, include appropriate safeties, and so on.) – David Schwartz Nov 04 '11 at 00:10
  • @DavidSchwartz I think this is very important. sudo is not quite same because it allows user to delete anything – Miserable Variable Jun 04 '13 at 18:14
  • @DavidSchwartz Can I upvote this 500 times? A system tool broke my home directory by putting a directory in it without adding group permissions... Let's add a feature request to... Linux? – ADJenks Nov 22 '18 at 18:49
  • Where is the official explanation on why is it possible to delete third-party empty directories while the same is not possible for non-empty ones?. – Jaime Hablutzel Nov 12 '19 at 00:13
  • @JaimeHablutzel It's the consequence of two independent things really. 1. Deleting a file or directory is the modification of the containing directory, not of the file/directory that you delete. So you need permission for the containing directory only (unless sticky bit is set). 2. But, regardless of permission matters, you can't delete a non-empty directory. So it has to be emptied first, and you might not have the permission for that, but that's technically a separate operation. – ddekany May 06 '20 at 13:58
1

You could add your account to sudoers and 'sudo rm -R' the folder.

I am not aware of a setting you can apply to do it normally.

Toby
  • 729
-1

logically you should if the directory is yours and is writeable. However i have heard of a subdirectory that you cannot write to preventing removing the folder/deleting files.

If you like try the command rm -f filename or rm -rf dir to remove a directory.

  • Nope, that won't work if "dir" contains files and you don't have write permission on them. See the accepted answer for details. – Alex Oct 20 '23 at 09:26