Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rm: cannot remove: Permission denied [closed]

Tags:

linux

bash

    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?

like image 725
Nikolay Baluk Avatar asked Nov 17 '11 23:11

Nikolay Baluk


People also ask

How do you remove denied permissions in Linux?

To fix the permission denied error in Linux, one needs to change the file permission of the script. Use the “chmod” (change mode) command for this purpose.

How do I remove permissions from a directory in Linux?

To remove world read permission from a file you would type chmod o-r [filename]. To remove group read and execute permission while adding the same permission to world you would type chmod g-rx,o+rx [filename]. To remove all permissions for group and world you would type chmod go= [filename].


1 Answers

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.

like image 143
Robᵩ Avatar answered Sep 20 '22 12:09

Robᵩ