Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use wildcard with files which names start with '-'?

Tags:

bash

shell

macos

There are some files which names start with '-', such as '-1.png', '-2.png'. I can't operate them with wildcard, because those names are regarded as options:

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

How to solve this problem?

like image 994
user805627 Avatar asked Jan 15 '23 05:01

user805627


1 Answers

Either use

ls -- *.png

or

ls ./*.png

The double dash is a common option in GNU tools to signify the end of options: any subsequent words starting with dash is a plain argument. rm works the same way.

like image 67
glenn jackman Avatar answered Jan 23 '23 23:01

glenn jackman