该命令rm -rf ./
不会在充满子目录和文件的目录中执行任何操作。为什么这样?不-r
应该递归吗?
更令人困惑的是,它甚至会打印一条错误消息,表明它正在遍历目录:
rm: refusing to remove ‘.’ or ‘..’ directory: skipping ‘./’
Run Code Online (Sandbox Code Playgroud)
该rm
命令拒绝通过“.”删除目录。姓名。如果您改为使用完整路径名,则应递归删除该目录。
如果目录是当前目录,也可以删除该目录。
[testuser@testhost] /tmp$ mkdir ff
[testuser@testhost] /tmp$ cd ff
[testuser@testhost] /tmp/ff$ touch a b c
[testuser@testhost] /tmp/ff$ rm -rf ./
rm: cannot remove directory: ‘./’
[testuser@testhost] /tmp/ff$ ls
a b c
[testuser@testhost] /tmp/ff$ rm -rf /tmp/ff
[testuser@testhost] /tmp/ff$ ls
[testuser@testhost] /tmp/ff$ ls ../ff
ls: cannot access ../ff: No such file or directory
[testuser@testhost] /tmp/ff$ cd ..
[testuser@testhost] /tmp$ ls ff
ls: cannot access ff: No such file or directory
Run Code Online (Sandbox Code Playgroud)
来自info rm
:
任何删除最后一个文件名组件为.'
or
..'的文件的尝试都会被拒绝,没有任何提示。