Wildcards
Wildcards provide a shorthand for specifying sets of files with similar names. For example, a* means all files whose names begin with lowercase “a”. Wildcards are “expanded” by the shell into the actual set of filenames they match. So if you type:
$ ls a*
the shell first expands a* into the filenames that begin with “a” in your current directory, as if you had typed:
ls aardvark adamantium apple
ls never knows you used a wildcard: it sees only the final list of filenames after the shell expansion.
Wildcard | Meaning | |
* | Any set of characters except a leading period | |
? | Any single character | |
[ | Any single character in the given | |
[ [ | Any single character not in the given |
When using sets, if you want to include a literal dash in the set, put it first or last. To include a literal closing square bracket in the set, put it first. To include a ^ or ! literally, don’t put it first.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access