08. Globbing and Wildcards *, ?

We can use wildcards to specify some group of characters. For example, suppose we only want the details of the files that have a .html extension.

We can either type:

$ ls -l helloWorld.html
$ ls -l helloWorld2.html
...and so on...

Or...we can use a wildcard, and list all of them in one go!

$ ls -l *.html

The power of the *

The * symbol is known as a wildcard. It stands in place of any text or number, no matter the length. We also have other variables and notations we can use for wildcards:

*
0 or any number of characters.
?
Any one character.
[abc]
The characters a, b, or c.
[!aeiou]
Any non-vowel character.
[a-m]
Characters from a to m (alphabetical).
[2-9]
From number 2 up to 9.

Additionally, we can specify wildcard classes.

[[:alnum:]]
Any alphanumeric character.
[[:alpha:]]
Any alphabet character.
[[:digit:]]
Any numberal.
[[:lower:]]
Any lowercase letter.
[[:upper:]]
Any uppercase letter.

In the next section, we'll see how we can expand these wildcards out to see exactly what they hold.

Aching back from coding all day?

Acupressure Mat & Pillow

Aching back from coding all day? Try Back Problems

Relieve your stress, back, neck and sciatic pain through 1,782 acupuncture points for immediate neck pain relief. Made for lower, upper and mid chronic back pain treatment, and improves circulation, sleep, digestion and quality of life.

$$ Check price
144.87144.87Amazon 4.5 logo(1,890+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

Command Line Kung Fu

Take your Linux skills to the next level! Try Linux & UNIX

Command Line Kung Fu is packed with dozens of tips and practical real-world examples. You won't find theoretical examples in this book. The examples demonstrate how to solve actual problems. The tactics are easy to find, too. Each chapter covers a specific topic and groups related tips and examples together.

$ Check price
14.9914.99Amazon 4.5 logo(27+ reviews)

More Linux & UNIX resources

Ad