"Taking a LiveFire Labs' course is an excellent way to learn
Linux/Unix. The lessons are well thought out, the material is
explained thoroughly, and you get to perform exercises on a real
Linux/Unix box. It was money well spent."
Ray S.
Pembrook Pines, Florida
LiveFire Labs' UNIX and Linux Operating System Fundamentals
course was very enjoyable. Although I regularly used UNIX systems
for 16 years, I haven't done so since 2000. This course was a
great refresher. The exercises were fun and helped me gain a real
feel for working with UNIX/Linux OS. Thanks very much!"
Ming Sabourin
Senior Technical Writer
Nuance Communications, Inc.
Montréal, Canada
Read
more student testimonials...
Receive UNIX Tips, Tricks, and Shell Scripts by Email
LiveFire Labs' UNIX Tip,
Trick, or Shell Script of the Week
UNIX Special Characters (Metacharacters) - Asterisk, Question
Mark, Brackets, and Hyphen
Special Characters (Metacharacters)
Special characters, or metacharacters, have a special meaning to the
shell. They can be used as wildcards to specify the name of a file
without having to type out the file's full name. Some of the most
commonly used metacharacters are "*", "?", "[]", and "-".
The Asterisk
The * (asterisk) metacharacter is used to match any and all
characters. Typing the following command will list all files in the
working directory that begin with the letter l regardless of what
characters come after it:
$ ls l*
The * (asterisk) metacharacter can be used anywhere in the filename.
It does not necessarily have to be the last character.
The Question Mark
The ? (question mark) metacharacter is used to match a single
character in a filename. Typing the following will list all of the
files that start with "livefirelabs" and end with a single character:
$ ls livefirelabs?
Like the asterisk, the ? (question mark) metacharacter can be used as
a substitution for any character in the filename.
Brackets
Brackets ([…]) are used to match a set of specified characters. A
comma separates each character within the set. Typing the following
will list all files beginning with "a", "b", or "c":
$ ls [a,b,c]*
The Hyphen
Using the - (hyphen) metacharacter within [] (brackets) is used to
match a specified range of characters. Typing the following will list
all files beginning with a lowercase letter of the alphabet:
$ ls [a-z]*
If there are directory names meeting the specified range, their name
and contents will also be displayed.
TIP: Although possible, it is highly recommended that
you do not create file names containing metacharacters.