有一些文件名以“-”开头,例如“-1.png”、“-2.png”。我不能用通配符操作它们,因为这些名称被视为选项:
bash-3.2$ ls *.png
ls: illegal option -- .
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
bash-3.2$ rm *.png
rm: illegal option -- 1
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题呢?
要么使用
ls -- *.png
Run Code Online (Sandbox Code Playgroud)
或者
ls -- *.png
Run Code Online (Sandbox Code Playgroud)
双破折号是 GNU 工具中用于表示选项结束的常用选项:任何以破折号开头的后续单词都是一个普通的参数。
rm工作方式相同。