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.

Take your Linux skills to the next level!

System Admin Handbook

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

This book approaches system administration in a practical way and is an invaluable reference for both new administrators and experienced professionals. It details best practices for every facet of system administration, including storage management, network design and administration, email, web hosting, scripting, and much more.

$ Check price
74.9974.99Amazon 4.5 logo(142+ reviews)

More Linux & UNIX resources

Aching back from coding all day?

Inversion Therapy Table

Aching back from coding all day? Try Back Problems

Stretch out your back and relieve your back muscles with inversion therapy. This device counteracts the forces of gravity on the body by decompressing and elongating the spine. By using this product just ten minutes a day, you can be well on your way to improved circulation and posture while relieving muscle aches, back pain and stress.

$$ Check price
119.98119.98Amazon 4.5 logo(1,700+ reviews)

More Back Problems resources

Ad