Thursday, February 9, 2012

Unix Tools - Wild cards (Filename Shorthand or meta Characters)

Wild card /ShorthandMeaningExamples
* Matches any string or group of characters.$ ls *will show all files
$ ls a* will show all files whose first name is starting with letter 'a'
$ ls *.c   will show all files having extension .c
$ ls ut*.c will show all files having extension .c but file name must begin with 'ut'.
? Matches any single character.$ ls ?   will show all files whose names are 1 character long 
$ ls fo? will show all files whose names are 3 character long and file name begin with fo
[...] Matches any one of the enclosed characters $ ls [abc]*  will show all files beginning with letters a,b,c
Note:
[..-..] A pair of characters separated by a minus sign denotes a range.
Example:
$ ls /bin/[a-c]*
Will show all files name beginning with letter a,b or c like
   /bin/arch           /bin/awk           /bin/bsh     /bin/chmod           /bin/cp
   /bin/ash           /bin/basename   /bin/cat      /bin/chown           /bin/cpio
   /bin/ash.static   /bin/bash          /bin/chgrp   /bin/consolechars  /bin/csh
But
$ ls /bin/[!a-o]
$ ls /bin/[^a-o]

If the first character following the [ is a ! or a ^ ,then any character not enclosed is matched i.e. do not show us file name that beginning with a,b,c,e...o, like
   /bin/ps            /bin/rvi              /bin/sleep /bin/touch      /bin/view
   /bin/pwd           /bin/rview        /bin/sort   /bin/true        /bin/wcomp
   /bin/red           /bin/sayHello     /bin/stty   /bin/umount   /bin/xconf
   /bin/remadmin  /bin/sed           /bin/su      /bin/uname     /bin/ypdomainname
   /bin/rm            /bin/setserial    /bin/sync   /bin/userconf  /bin/zcat
   /bin/rmdir         /bin/sfxload      /bin/tar    /bin/usleep
   /bin/rpm           /bin/sh            /bin/tcsh    /bin/vi

No comments:

Post a Comment