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!

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

Aching back from coding all day?

Self-Massage Tool

Aching back from coding all day? Try Back Problems

Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.

$ Check price
29.9529.95Amazon 4.5 logo(3,443+ reviews)

More Back Problems resources

Ad