|
Unix : File Name Substitution
Fine name substitution is a feature which allows strings
to be substituted for pattern and special characters. This provides greater
flexibility and saves a lot of typing time.
The
*
character matches any zero or more characters. This is one of the most
frequently used pattern matching character. If used alone, * substitutes the
names of all the files in the current directory, except those that begin with
the “.” character. The “.” character must be explicitly matched.
Usage: cat * ls
* ls m* ls *2 ls */*.a
The ? character matches
exactly one character. It is useful when the file name matching criteria is the
length of the file name.
If you want to list the
file names in the current directory that had at least three or more characters
in the name. Usage would be ls ???*.
The [ ] character match
a single, multiple, or range of characters. It is useful when you want to match
certain characters in a specific position in the file name.
Usage would be ls
[am]* would output a ab abc mob1 mob2
The ! character can be
used with [ ] to reverse the match. In other words, [!a] matches any character,
except a.
Certain characters such
as “.” must be explicitly matched. This command matches the file .a , .b, .c,
and .d.
Usage: ls .[a-d]
|