Wildcards
Wildcards are a convenient way to select items matching patterns.
Let’s list the files in the molecules
directory:
ls
cubane.pdb ethane.pdb methane.pdb octane.pdb pentane.pdb propane.pdb
You could do the same with:
ls *
The star expands to all files/directories matching any pattern. It is a wildcard.
Of course, you can match more interesting patterns.
For instance, to list all files starting with the letter o
, we can run:
ls o*
octane.pdb
To list all files containing the letter o
anywhere in their name, you can use:
ls *o*
octane.pdb propane.pdb
This saves a lot of typing and is a powerful way to apply a command to a subset of files/directories.
Your turn:
Wildcards are often used to select all files with a certain extension.
Let’s create 3 new files:
touch file1.txt file2.txt file3.md
How would you list all files with the .txt
extension and only those?