bash rm 无法删除以“--”开头的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13917714/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
rm cannot delete files starting with "--"
提问by frazras
I have a script that creates files, and sometimes they end up having two dashes at the beginning. Is there any way to delete them? mvdoesn't work either.
我有一个创建文件的脚本,有时它们的开头有两个破折号。有什么办法可以删除它们吗?mv也不起作用。
Here is the error I am getting:
这是我得到的错误:
$ 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
回答by Lev Levitsky
The usual trick is
通常的技巧是
rm ./--1355509766.jpg
Update: here's what man rmhas to say about this:
更新:以下是man rm对此的看法:
To remove a file whose name starts with a '-', for example '-foo', use
one of these commands:
rm -- -foo
rm ./-foo
回答by dogbane
Use --to separate options from parameters.
使用--从参数不同的选项。
$ rm -- --1355509766.jpg
This works with other commands too. For example:
这也适用于其他命令。例如:
$ touch -- -v # create a file called -v
$ grep foo -- -v # grep for "foo" in file called -v
回答by Rasim
Try file name with path:
尝试带路径的文件名:
$ rm ./--file.name
Example:
例子:
$ echo dgag > --test.txt
$ ls
--test.txt
$ rm ./--test.txt
$ ls

