What is file globbing?

Globbing is the * and ? and some other pattern matchers you may be familiar with.

Globbing interprets the standard wild card characters * and ?, character lists in square brackets, and certain other special characters (such as ^ for negating the sense of a match).

When the shell sees a glob, it will perform pathname expansion and replace the glob with matching filenames when it invokes the program.

For an example of the * operator, say you want to copy all files with a .jpg extension in the current directory to somewhere else:

cp *.jpg /some/other/location

Here *.jpg is a glob pattern that matches all files ending in .jpg in the current directory. It’s equivalent to (and much easier than) listing the current directory and typing in each file you want manually:

$ ls
cat.jpg dog.jpg drawing.png recipes.txt zebra.jpg

$ cp cat.jpg dog.jpg zebra.jpg /some/other/location

Note that it may look similar, but it is not the same as Regular Expressions.

You can find more detailed information here and here

Leave a Comment