graphics\overbutt.gifUnderstanding wildcards

Wildcards help you use pattern matching to search for files. You can also use wildcards to perform the same command on a group of files. Wildcards can be used on their own, together, or with other letters and numbers. The following list outlines three wildcards that bash supports.

For example, assume you have the following files in your current directory.

test1.txt test2.txt test3.txt draw1 draw2 lorem

You can list only the files that begin with "t" using the asterisk (*) wildcard.

Mabel~:$ ls t*

test1.txt test2.txt test3.txt

You can use the question mark (?) wildcard to list files with only five characters in the filename.

Mabel~:$ ls ?????

draw1 draw2 lorem

You can also combine the asterisk (*) and brackets [...] wildcards to copy only files with the numbers one and two in the filename to a directory called new.

Mabel~:$ cp *[1-2]* new

Based on the above example, the files copied to the new directory include: draw1 draw2 test1.txt test2.txt.