小知识点:Linux删除‘-’开头的文件

187 阅读1分钟

先看两个特殊文件(以-开头)

[root@node_119 test]# ll
total 0
-rw-r--r-- 1 root root 0 Aug  3 08:59 -rf *
-rw-r--r-- 1 root root 0 Aug  3 09:00 -test

上面两个文件用普通方法无法删除

[root@node_119 test]# rm '-rf *' 
rm: invalid option -- ' '
Try 'rm ./'-rf *'' to remove the file ‘-rf *’.
Try 'rm --help' for more information.
[root@node_119 test]# rm -rf\ \* 
rm: invalid option -- ' '
Try 'rm ./'-rf *'' to remove the file ‘-rf *’.
Try 'rm --help' for more information.

删除方法,在文件名前加--

[root@node_119 test]# rm -rf -- '-rf *'
[root@node_119 test]# rm -rf -- -test
[root@node_119 test]# ll
total 0

两个文件已被删除,点个赞