这对我来说似乎很奇怪。我正在运行内核 2.6.37.2 并运行:
~]$ cp -r /proc/ here
~]$ rm -rf here
Run Code Online (Sandbox Code Playgroud)
我在按预期复制时得到了一些许可被拒绝,我最终点击了 Control-C。Permission denied
尝试删除新目录和文件时,我得到了很多文件。
请注意,我发现这种奇怪的行为是因为一位朋友给我发送了.tgz
他/proc
目录的快照。我提取了目录,当我完成查看它时,我遇到了同样的问题。
rm -rf
因为 root 确实有效。
lsattr
显示 e 属性(这是我所有文件/目录所显示的)。
Gil*_*il' 16
如果存在您没有写权限的非空目录,则无法删除其内容。
$ mkdir foo
$ touch foo/bar
$ chmod a-w foo
$ rm -rf foo
rm: cannot remove `foo/bar': Permission denied
Run Code Online (Sandbox Code Playgroud)
原因是它rm
像任何其他命令一样受权限约束,删除bar
权限需要对foo
. 这在您rm
以 root 身份运行时不适用,因为 root 始终具有删除文件的权限。
要使目录树可删除,请将其中的所有目录设为可写(使用 删除时,常规文件的权限无关紧要rm -f
)。您可以使用以下任一命令:
chmod -R u+w here # slow if you have a lot of regular files
find here -type d -exec chmod u+w {} +
Run Code Online (Sandbox Code Playgroud)