CHMOD 防止删除文件目录

Fen*_*ton 4 linux hosting permissions chmod

我在 Linux 服务器上有一些主机,我有一些我不想删除的文件夹。其中有我想要删除的子文件夹。

如何为不想删除的文件夹设置 CHMOD 权限?

当然,当我说“我永远不想删除”时 - 我的意思是最终客户不应该通过 FTP 或 PHP 脚本等意外删除它们。

作为目录结构的示例...

MainFolder/SubFolder
MainFolder/Another
Run Code Online (Sandbox Code Playgroud)

我不希望“MainFolder”被意外删除,但我很高兴删除“SubFolder”和“Another”!

Sha*_*hin 11

删除文件/目录会更改父目录的内容,因此,如果您不想MainFolder被删除,您需要确保目标用户对MainFolder.

假设这种结构: /some/dir/ParentDir/MainFolder/SubFolder

你会想要运行这样的东西来防止删除(对于所有用户):

chmod a-w /some/dir/ParentDir

当然,这不是理想的情况,因为使其不可写意味着用户无法向其中添加其他文件/目录 /some/dir/ParentDir

粘性位会更适合您的目的吗?在父目录上设置粘滞位将只允许目录所有者删除。

chmod +t /some/dir/ParentDir

有关粘滞位的更多信息,请查看http://en.wikipedia.org/wiki/Sticky_bit上的使用部分。