rm: cannot remove directory/: Permission denied

Here the problem is you do not have "w" permission on the /home directory. While deleting a file note that you are not writing to that file but you are changing the contents of the directory that contains the file, so having "w" permission on the directory is a must if you want to delete any file from the directory.

terminal screenshot of "ls -ld /home"

If I am in a directory with "w" permission, I can delete any of its files without being worried about the file permission itself. Note that my present directory is /home/rohith which has "w" permission and hence I can delete any of its files irrespective of the file permissions.

terminal screenshot of removing /home/rohith/shadi

If the same file is created in the '/home' directory which has no "w" permission I get the same output as yours ! :)

terminal screenshot of trying to remove /home/shadi


This happens because you don't own the directory, it is owned by 'root' and the 'root' group. So to delete it you can either changing the ownership and then delete it (here you elevate your rights and become 'root' for taking the ownership):

sudo chown $USER:$USER ./shadi
rm -r ./shadi

Or you skip taking the ownership and make a sudo rm to elevate your rights and become 'root' for the deletion:

sudo rm -r ./shadi

Try this:

sudo rm -r ./shadi

The permissions show owner root and group root, so you have to use sudo.

Tags:

Permissions

Rm