"rm -rf ./"が何も削除しないのはなぜですか?

このコマンドは、rm -rf ./サブディレクトリとファイルでいっぱいのディレクトリでは何もしません。なぜこれですか?再帰的でなければなりませんか-r

混乱を加えるためにディレクトリを巡回していることを示すエラーメッセージも印刷します。

rm: refusing to remove ‘.’ or ‘..’ directory: skipping ‘./’

ベストアンサー1

このrmコマンドは「。」ディレクトリ名の削除を拒否します。フルパス名を使用する場合は、ディレクトリを繰り返し削除する必要がありますrm -rf `pwd`‌。つまり、 。

現在のディレクトリの場合は、そのディレクトリを削除することもできます。

[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

からinfo rm

最後のファイル名部分が..'のファイルを削除しようとすると、.' or プロンプトなしで拒否されます。

おすすめ記事