rm: cannot remove: Permission denied

LinuxBash

Linux Problem Overview


    max@serv$ whoami
    max
    max@serv$ ls -la ./defines.php 
    -rwxrwxrwx 1 max max 1985 2011-11-16 02:01 ./defines.php
    max@serv$ chmod 0777 ./defines.php 
    max@serv$ rm ./defines.php 
    rm: cannot remove `./defines.php': Permission denied
    max@serv$

How can I delete this file?

Linux Solutions


Solution 1 - Linux

The code says everything:

max@serv$ chmod 777 .

Okay, it doesn't say everything.

In UNIX and Linux, the ability to remove a file is not determined by the access bits of that file. It is determined by the access bits of the directory which contains the file.

Think of it this way -- deleting a file doesn't modify that file. You aren't writing to the file, so why should "w" on the file matter? Deleting a file requires editing the directory that points to the file, so you need "w" on the that directory.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNikolay BalukView Question on Stackoverflow
Solution 1 - LinuxRobᵩView Answer on Stackoverflow