Linux 删除横杆“-”开头文件

  偶尔遇到,记录下。感觉这个怪怪的,毕竟以横岗开头会让程序认为这是一个选项,因此不大好处理,只要让相同的文件以不同的形式去表达,如./-G./表示当前文件夹,所以能够解决这一问题,虽说有提示,但重来不看。

root@pi:~# rm -rf -G
rm: invalid option -- 'G'
Try `rm ./-G' to remove the file `-G'.
Try `rm --help' for more information.
root@pi:~# rm -rf "-G"
rm: invalid option -- 'G'
Try `rm ./-G' to remove the file `-G'.
Try `rm --help' for more information.
root@pi:~# ls
-G  t.txt
root@pi:~# rm -rf *
rm: invalid option -- 'G'
Try `rm ./-G' to remove the file `-G'.
Try `rm --help' for more information.
root@pi:~# ls
-G  t.txt
root@pi:~# ls
-G  t.txt
root@pi:~# rm -rf t.txt
root@pi:~# ls
-G
root@pi:~# rm -rf "-G"
rm: invalid option -- 'G'
Try `rm ./-G' to remove the file `-G'.
Try `rm --help' for more information.
root@pi:~# ls
-G
root@pi:~# rm -rf "\-G"
root@pi:~# ls
-G
root@pi:~# rm -rf .\-G
root@pi:~# ls
-G
root@pi:~# rm -rf ./-G
root@pi:~# ls
root@pi:~#

15条评论在“Linux 删除横杆“-”开头文件”

  1. 可以使用带路径的文件描述操作“-[d]*”这样的文件,rename,remove都可以,比如
    # rm
    ➜ mytemp ls -l
    total 4
    -rw-rw-r– 1 johnny johnny 29 Oct 3 14:42 –
    ➜ mytemp rm ../mytemp/-
    ➜ mytemp ls
    ➜ mytemp
    #mv
    ➜ mytemp ls -l
    total 4
    -rw-rw-r– 1 johnny johnny 29 Oct 3 14:50 -d
    ➜ mytemp mv ../mytemp/-d ../mytemp/dat
    ➜ mytemp ls
    dat
    ➜ mytemp

回复 恋羽   取消