Linux – Does the “w” permission bit on a directory allow you to delete the directory

linuxpermissions

This tutorial says the following:

For a directory, write permission allows a user to delete the
directory
, modify its contents (create, delete, and rename files in
it), and modify the contents of files that the user can read.

To test this, I created a directory named subdir that doesn't have the w permission bit, and I placed it inside a directory named dir that have the w and the x permission bits set:

d-wx------ 3 robert robert 4096 2017-12-16 9:07 dir
d--------- 3 robert robert 4096 2017-12-16 9:07 subdir

And I was able to delete subdir from the robert account.

So does the tutorial I have linked to give wrong information, or am I missing something?

Best Answer

It's wrong. To delete something you need write permissions on the directory containing it. That also goes for directories themselves: to delete a directory, you need (at a minimum) write permissions on the parent directory. You may need write permissions on the directory as well, but that's not enough by itself.

Write permissions on the directory itself are needed when the directory is not empty. In that case, you need to clear out the directory first by deleting everything in it, so you need write permissions on all sub-directories as well (recursively). Then you can delete the directory itself if you have write permissions on the parent.