How to use wildcards, by The Linux Masters Wiki: The usage of wildcards is a nice feature that the shell provides us. Simple characters such as * or ? can make our bash life much more easier than we have ever imagined.
Wildcards are special characters that allow us to select a big number of files that match a specified pathern. The most common are the asterisk * and the question mark ? , which I will teach you in the article.
Every shell has it’s own wildcards! Not all the bash wildcards work in zsh, for example!
The bash asterisk * wildcard:
The asterisk represents zero or more characters:
The following command will move the .txt files to ~/dir :
a.txt bb.txt ccc.txt d e f
$ mv *.txt ~/dir
$ ls ~/dir
a.txt bb.txt ccc.txt
The bash question mark ? wildcard:
The question mark represents only one character.
ls ??.txt lists all the files with the .txt extension that have only two characters in their name and ls ? lists all the files with names containing only one character:
a.txt bb.txt ccc.txt d e f xx.txt
$ ls ??.txt
$ ls ?
d e f