1. Home
  2. Docs
  3. Beginning UNIX on Raven
  4. Files and navigation
  5. Wildcards

Wildcards

Sometimes we just don’t know what we want!  Wildcards can be thought of as a way of searching multiple options at the same time and returning all the results together.  So if we want to search for all files in our /home/pi/files directory that start with f, we can just type:

ls f*

file1  file2  file3  file4  file5

The wildcard * has a specific meaning of nothing or a string of characters of any length.  So a search for f* would also return a file called f if it existed in our directory.  Likewise a file called floccinaucinihilipilification (the action or habit of estimating something as worthless) would be returned if present.

To search for all files which have a 1 as their final character we can use:

ls *1

blank1  file1  text1

Wildcards work with many different programs that can accept multiple files in their input, so for example we can check out the file types of all files ending with a 1 using:

file *1

blank1: empty

file1:  ASCII text

text1:  ASCII text

If we want to search for files with the prefix of text, then we can use the ? wildcard which will match any single character.

ls text?

text1  text2  text3  text4  text5

To search for files that have 4 characters followed by the number 1 we can use:

ls ????1

file1  text1

Finally using brackets we can specify specific matches or ranges.  So to find all files with a prefix of file and an ending between 1 and 3:

ls file[1-3]

file1  file2  file3

Multiple options can be specified with commas within the brackets (e.g. [1-3,7-9]), include ranges of letters (e.g. [a-z] or [A-Z]), or be combined to specifiy for example just letters and numbers [a-z,A-Z,0-9].