The wildcards in Unix

Although the command line makes Unix über powerful, it is really the subtleties of things such as wildcard characters where the true power lies. Here are two: * and ?

The asterisk, *, matches zero or more characters. For example, a* matches the files a , ab , abc , abc.d

The question mark, ?, matches exactly one character. For example, a? matches aa , ab , ac , etc.

For example, to find all the files ending in .sh in the current directory, using the find command:

find . -name '*.sh'

To list all files that begin with “f1”, but have any value for the third position using the ?:

ls f1?

Or, you can combine the two:

find . -name '7_1?0.*'

In this example find will find all files that begin with “7_1”, have any character for the 4th term, have “0.” for the next two terms, and any terminating characters (either in type or length).


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s