当我们使用 rm 命令删除一些特别的文件的时候有可能会出现 rm: unrecognized option
的问题 如下 就算加了 -rf
依旧不好使
[root@izuf66bc6zb0cuc0f7x9krz movie]# rm --hello
rm: unrecognized option '--hello'
Try 'rm ./--hello' to remove the file ‘--hello’.
Try 'rm --help' for more information.
[root@izuf66bc6zb0cuc0f7x9krz movie]# rm -rf --hello
rm: unrecognized option '--hello'
Try 'rm ./--hello' to remove the file ‘--hello’.
Try 'rm --help' for more information.
- 我们检查后会发现 这些难以删除的特殊的文件 文件名中都带有
-
- 原来 linux 会把
-文件名
当成-参数
- 举个例子 就相当于
rm --hello
系统把--hello
当成像是rm -rf
当中-rf
一样的参数了 - 而事实上是没有
--hello
这样的参数的 所以系统会报错 不能识别操作
解决这个问题的方式非常的简单 就是在 rm
后面加上--
就可以了
如删除 --hello
可以写成 rm -- --hello
这是因为shell把 --
之后的参数当做文件名来对待 禁止把-filename当做参数选项来解释 所以能够正确的执行shell命令