这个问题在这里已有答案:
我有一个创建文件的脚本,有时它们最初会有两个破折号。有没有办法删除它们? mv
也不起作用。
这是我得到的错误:
$ ls
--1355509766.jpg
$ rm --1355509766.jpg
rm: illegal option -- -
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
$ rm "--1355509766.jpg"
rm: illegal option -- -
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
通常的伎俩是
rm ./--1355509766.jpg
更新:这是man rm
对此的评价:
To remove a file whose name starts with a '-', for example '-foo', use
one of these commands:
rm -- -foo
rm ./-foo
使用--
将选项与参数分开。
$ rm -- --1355509766.jpg
这也适用于其他命令。例如:
$ touch -- -v # create a file called -v
$ grep foo -- -v # grep for "foo" in file called -v
尝试使用路径的文件名:
$ rm ./--file.name
例:
$ echo dgag > --test.txt
$ ls
--test.txt
$ rm ./--test.txt
$ ls