Linux rm:无法删除:权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8175697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 02:21:13  来源:igfitidea点击:

rm: cannot remove: Permission denied

linuxbash

提问by Nikolay Baluk

    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?

我怎样才能删除这个文件?

采纳答案by Rob?

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 notdetermined by the access bits of that file. It is determined by the access bits of the directory which contains the file.

在 UNIX 和 Linux 中,删除文件的能力取决于该文件的访问位。它由包含文件的目录的访问位决定。

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.

这样想——删除文件不会修改该文件。您没有写入文件,那么为什么文件上的“w”很重要?删除文件需要编辑指向该文件的目录,因此您需要在该目录上添加“w”。