HOWTO: Use Shell Wildcards
We’re all familiar with some of the more common wildcard characters like * and ?, but most shells offer a lot more than that.
First off, there’s some invisible magic that most of us probably don’t care about, but should be mentioned. When your hacking away at the command line, you’re actually operating within a ’shell’. Probably the most common shell on GNU/Linux systems is the Bourne Again Shell which is typically just called BASH. The shell takes the commands you type in, does whatever needs to be done to them, and passes them off to the system to deal with. I’m gonna go way out on a limb here and state that the shell is also responsible for presenting the output from said commands back to you.
Now that we (kinda) understand that, I can take it one step further. When you use wildcards, it’s actually the shell that expands those tokens into meaningful data before passing them off to the system.
WIthin BASH, there are some pretty handy wildcards:
| * | Match zero or more characters | *a.txt matches 12dsa.txt and a.txt but not 3gff.txt |
| ? | Match exactly one character | ??.c matches 2c.c and cc.c, but not edf.c |
| [characters] | matches specified characters | a[bc] matches ab and ac, but not ad |
| [!characters] | matches characters NOT specified | a[!bc] matches ad, but not ac or ab |
| [a-z] | matches range of characters | 1[a-c] matchez 1a and 1b but not 1g. Can also be used with numbers [0-9] and is case sensitive [a-zA-Z] matches all letters regardless of case |
There is another useful wildcard that uses the brace {} characters to construct filenames. That’s the subject of another entry, though. I’ll link to it here when I write it.
Related Stories
POSTED IN: How To
0 opinions for HOWTO: Use Shell Wildcards
No one has left a comment yet. You know what this means, right? You could be first!
Have an opinion? Leave a comment: