Can't remove directory that I'm owner of

The issue is you're not the owner nor part of the group of the parent folder and that is what's blocking you. Run the same command with sudo in front of it without modifying the permissions or ownership of the /var/www/ folder.

sudo rm -R mage/

Folders inherit the permissions from their parent folders. When you are the owner of the mage/ folder, that will allow you to create new folders and files and delete them within the mage/ folder. But, since the mage/ folder is a subfolder of the /var/www/ folder, which you do not have write or execute permissions to, you cannot create files or folders without sudo permission or changing the ownership or permissions of /var/www/. If /var/www/ had permissions of drwxrwxrwx that would allow you as a user to delete that folder, but this is not recommended as it could break your apache2 server.

Your folder inherited the same permissions as its parent folder that is why you cannot delete the folder as a regular user.

Hope this helps!


I had a similar issue

It turned out I had a process currently using the directory I was trying to remove (namely: Visual Studio Code)

When I shut down Visual Studio Code, I was able to delete the directory without any issue