3.3. Shell Globbing Patterns

You probably already use globbing characters without knowing it. When you specify a file in Windows or when you look for a file, you use * to match a random string. For example, *.txt matches all files with names ending with .txt. We also used it heavily in the last section. But there is more to globbing than just *.

When you type a command like ls *.txt and press Return, the task of finding which files match the *.txt pattern is not done by the ls command, but by the shell itself. This requires a little explanation about how a command line is interpreted by the shell. When you type:

$ ls *.txt
readme.txt  recipes.txt

the command line is first split into words (ls and *.txt in this example). When the shell sees a * in a word, it will interpret the whole word as a globbing pattern and will replace it with the names of all matching files. Therefore, the command, just before the shell executes it, has become ls readme.txt recipe.txt, which gives the expected result. Other characters make the shell react this way:

Here are some patterns and their meaning:

Notes

[1]

Beware! While this is true under GNU/Linux, this may not be true under other Unix-like operating systems. This depends on the collating order. On some systems, [a-z] will match a, A, b, B, (...), z. And we do not even mention the fact that some languages have accentuated characters...


Tux on Star from MandrakeSoft Linux is a registered trademark of Linus Torvalds. All other trademarks and copyrights are the property of their respective owners.
Unless otherwise stated, all the content of these pages and all images are Copyright MandrakeSoft S.A. and MandrakeSoft Inc. 2001.
http://www.mandrakelinux.com/