Characters Are Wild
- 0
- Add a Comment
Characters Are Wild
I know we’ve talked a bunch about searching for files, strings and patterns in Linux. As you start to get comfortable with the shell and move around within it more and more, these commands really start to show their power. I want to take a paragraph or two to mention yet another ‘matching’ feature in Linux that will become more useful as you go. Just like the one-eyed jack in a game of Montana Red Dog, today’s GnomeTWEAK is on wildcards.
Wildcards in Linux, as in Windows, are useful for searching files or groups of files based on a single character or a group of characters. If you remember only part of a filename, or want to find a group of files with a common extension, wildcards are invaluable. Let’s talk first about single character wildcards in Linux,
| Wildcard | Matches |
| * | Any characters |
| ? | Any single character |
| [characters] | Any character that’s a member of the [set] |
| ![characters] | Any character that’s not a member of the [set] |
This looks, and really is, pretty simple. Using single wildcards can be useful, but the real power of wildcards lies in putting together patterns for searching.
| Pattern | Matches |
| * | All files |
| x* | All files beginning with the letter x |
| *.rpm | All files ending with the .rpm extension |
| bash?? | All files that start with bash and end with two characters |
| [abc]* | All files that begin with a, b or c and end with any other characters |
| [A-Z]* | Any filename that begins with an uppercase letter followed by any other characters |
| DAILY.[0-9][0-9][0-9] | Any file starting with DAILY containing an extension with any 3 numbers |
| ![a-z]* | Any filename that doesn’t begin with a lower case letter |
Used with our old favorite “find” command, wildcards can be a real timesaver when searching for files.
