Linux Tutorial 03

Wildcards

Wildcard Meaning
* Matches any characters
? Matches any single character
[characters] Matches any character that is a member of the set characters
[!characters] Matches any character that is not a member of the set characters
[[:class:]] Matches any character that is a member of the specified class

Character Classes

 

Character Class Meaning
[:alnum:] Matches any alpha numeric character
[:alpha:] Matches any alphabetic character
[:digit:] Matches any numeral character
[:lower:] Matches any lowercase letter
[:upper:] Matches any uppercase letter

Wildcard Examples

Pattern Matches
* All Files
$ ls -l *
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 100.100
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 200.200
-rw-r----- 1 zikzak u41687  0 Jul 19 17:09 300.300
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_1001.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_1002.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_1003.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_101.DAT
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_102.DAT
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_103.DAT
-rw-r----- 1 zikzak u41687  0 Jul 19 19:37 AIG_104.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 19:37 AIG_105.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:06 one.csv
-rw-r----- 1 zikzak u41687 13 Jul 18 22:02 one.txt
-rw-r----- 1 zikzak u41687  0 Jul 19 17:06 three.csv
-rw-r----- 1 zikzak u41687 12 Jul 18 22:02 three.txt
-rw-r----- 1 zikzak u41687  0 Jul 19 17:06 two.csv
-rw-r----- 1 zikzak u41687  9 Jul 18 22:02 two.txt
o* Any file beginning with “o”
 $ ls -l o*
-rw-r----- 1 zikzak u41687  0 Jul 19 17:06 one.csv
-rw-r----- 1 zikzak u41687 13 Jul 18 22:02 one.txt
t*.csv Any file beginning with “t” followed by
any characters and ending with “.csv”
 $ ls -l t*.csv
-rw-r----- 1 zikzak u41687 0 Jul 19 17:06 three.csv
-rw-r----- 1 zikzak u41687 0 Jul 19 17:06 two.csv
AIG_???.dat Any file beginning with “AIG_” followed
by exactly three characters
 $ ls -l AIG_???.dat
-rw-r----- 1 zikzak u41687 0 Jul 19 19:37 AIG_104.dat
-rw-r----- 1 zikzak u41687 0 Jul 19 19:37 AIG_105.dat
[At3]* Any file beginning with either an “A”,
“t”, or  “3”
 $ ls -l [At3]*
-rw-r----- 1 zikzak u41687  0 Jul 19 17:09 300.300
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_1001.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_1002.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_1003.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_101.DAT
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_102.DAT
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_103.DAT
-rw-r----- 1 zikzak u41687  0 Jul 19 19:37 AIG_104.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 19:37 AIG_105.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:06 three.csv
-rw-r----- 1 zikzak u41687 12 Jul 18 22:02 three.txt
-rw-r----- 1 zikzak u41687  0 Jul 19 17:06 two.csv
-rw-r----- 1 zikzak u41687  9 Jul 18 22:02 two.txt
AIG_[0-9][0-9][0-9].DAT Any file beginning with “AIG_”
followed by exactly three numerals and ending with “.dat”
 $ ls -l AIG_[0-9][0-9][0-9].DAT
-rw-r----- 1 zikzak u41687 0 Jul 19 17:08 AIG_101.DAT
-rw-r----- 1 zikzak u41687 0 Jul 19 17:08 AIG_102.DAT
-rw-r----- 1 zikzak u41687 0 Jul 19 17:08 AIG_103.DAT
[[:upper:]]* Any file beginning with an uppercase letter
 $ ls -l [[:upper:]]*
-rw-r----- 1 zikzak u41687 0 Jul 19 17:08 AIG_1001.dat
-rw-r----- 1 zikzak u41687 0 Jul 19 17:08 AIG_1002.dat
-rw-r----- 1 zikzak u41687 0 Jul 19 17:08 AIG_1003.dat
-rw-r----- 1 zikzak u41687 0 Jul 19 17:08 AIG_101.DAT
-rw-r----- 1 zikzak u41687 0 Jul 19 17:08 AIG_102.DAT
-rw-r----- 1 zikzak u41687 0 Jul 19 17:08 AIG_103.DAT
-rw-r----- 1 zikzak u41687 0 Jul 19 19:37 AIG_104.dat
-rw-r----- 1 zikzak u41687 0 Jul 19 19:37 AIG_105.dat
[![:digit:]]* Any file not beginning with a numeral
 $ ls -l [![:digit:]]*
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_1001.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_1002.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_1003.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_101.DAT
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_102.DAT
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_103.DAT
-rw-r----- 1 zikzak u41687  0 Jul 19 19:37 AIG_104.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 19:37 AIG_105.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:06 one.csv
-rw-r----- 1 zikzak u41687 13 Jul 18 22:02 one.txt
-rw-r----- 1 zikzak u41687  0 Jul 19 17:06 three.csv
-rw-r----- 1 zikzak u41687 12 Jul 18 22:02 three.txt
-rw-r----- 1 zikzak u41687  0 Jul 19 17:06 two.csv
-rw-r----- 1 zikzak u41687  9 Jul 18 22:02 two.txt
 [[:digit:]]*  Any file only beginning with a numeral
 $ ls -l [[:digit:]]*
-rw-r----- 1 zikzak u41687 0 Jul 19 17:08 100.100
-rw-r----- 1 zikzak u41687 0 Jul 19 17:08 200.200
-rw-r----- 1 zikzak u41687 0 Jul 19 17:09 300.300
*[[:lower:]0123] Any file ending with a lowercase letter or
the numerals “0” or “1” or “2” or “3”
 $ ls -l *[[:lower:]0123]
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 100.100
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 200.200
-rw-r----- 1 zikzak u41687  0 Jul 19 17:09 300.300
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_1001.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_1002.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:08 AIG_1003.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 19:37 AIG_104.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 19:37 AIG_105.dat
-rw-r----- 1 zikzak u41687  0 Jul 19 17:06 one.csv
-rw-r----- 1 zikzak u41687  0 Jul 19 22:48 one.gz
-rw-r----- 1 zikzak u41687 13 Jul 18 22:02 one.txt
-rw-r----- 1 zikzak u41687  0 Jul 19 17:06 three.csv
-rw-r----- 1 zikzak u41687 12 Jul 18 22:02 three.txt
-rw-r----- 1 zikzak u41687  0 Jul 19 17:06 two.csv
-rw-r----- 1 zikzak u41687  9 Jul 18 22:02 two.txt
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s