CentOS Linux Server Guide

Centos Linux Files and Directories

Dealing files and directories with wildcards

 

Wildcards are very useful when you want to 'fuzzy logic' search with more than single files. Wildcards can be used either with only one character, or in combination with multiple characters

 
Wildcards Description
* match none or more characters

In below examples we list (ls) all files which start with y and end with conf. Another example Examplebelow shows we want to list all files start with e

ls y*.conf
yp.conf yum.conf


ls e*
enscript.cfg environment esd.conf exports

 

 

? match only one character

Example below shows we are going list rc?.d which ? represent only 1 character macthing.

ls -l rc?.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc0.d -> rc.d/rc0.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc1.d -> rc.d/rc1.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc2.d -> rc.d/rc2.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc3.d -> rc.d/rc3.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc4.d -> rc.d/rc4.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc5.d -> rc.d/rc5.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc6.d -> rc.d/rc6.d

 

 

[] match one characters in the []

Example below shows we are listing rc files where it match either 1 , 2 or 3 only

ls -l rc[123].d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc1.d -> rc.d/rc1.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc2.d -> rc.d/rc2.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc3.d -> rc.d/rc3.d

 

 

[a-d] match character a, b, c and d in the given range

The following example we are match rc files 1 to 5 ended with .d

ls -l rc[1-5].d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc1.d -> rc.d/rc1.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc2.d -> rc.d/rc2.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc3.d -> rc.d/rc3.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc4.d -> rc.d/rc4.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc5.d -> rc.d/rc5.d

 

 

[!a-d] Match any character other than in the given range within []

The following example will list out all rc files that are not with 1 to 3 ended with .d

ls -l rc[!1-3].d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc0.d -> rc.d/rc0.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc4.d -> rc.d/rc4.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc5.d -> rc.d/rc5.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc6.d -> rc.d/rc6.d
 

 

[!abcd] Match any character that is not listed in []

The following example tell the system to list the file which is not start with rc and has 1,2 or 3 in within the character and ended with .d

ls -l rc[!1,3,5].d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc0.d -> rc.d/rc0.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc2.d -> rc.d/rc2.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc4.d -> rc.d/rc4.d
lrwxrwxrwx 1 root root 10 Nov 26 19:32 rc6.d -> rc.d/rc6.d

 

 

Back to Files and Directories



Copyright 2011 http://www.1a-centosserver.com All Rights Reserved

All trademarks are the property of their respective owners.

Contact Us | Terms of Use | Privacy Policy