Neat Find Trick with Wildcards

Blasphemy! Originally, I had titled this post “Neat Find Trick with Regular Expressions”, but the use of brackets is not necessarily a regular expression. Turns out, it’s actually one type of wildcard character. So, the post title has been changed to “Neat Find Trick with Wildcards” to reflect this new knowledge (thanks Jim). Okay, onward…

This is one of those “how did I miss that while learning Linux” tips. You can use regular expressions (regex) wildcards in the terminal to simplify your life. For example, the find command can take advantage of this sorta thing. Say that you’re looking for all files ending with .c or .h. Instead of using the ‘find’ command twice, you can simply use “*.[ch]” to search for them. The brackets tell find to search for any single character within them. You can learn more about regular expressions here, wildcards here, but for now, let’s see this in action:

find . -type f -name "*.[ch]"

As expected, this will find all files that end in a .c or .h extension. Have fun!

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:

There's 1 Comment So Far

Share your thoughts, leave a comment!