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?

Foam Seat Cushion

Aching back from coding all day? Try Back Problems

This foam seat cushion relieves lowerback pain, numbness and pressure sores by promoting healthy weight distribution, posture and spine alignment. Furthermore, it reduces pressure on the tailbone and hip bones while sitting. Perfect for sitting on the computer desk for long periods of time.

$ Check price
99.9599.95Amazon 4.5 logo(9,445+ 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