Wlid Cards in Linux



Wild Cards :- 
A character or string used for pattern matching
Expand the wild card pattern into a list of file and/or directories.(path)
wild cards can be used with most commands ex:- ls, rm, cp etc

Some basic wild cards are:  
  • *  -  matches zero or more characters
  •  ?  -  matches exactly one characters
  •  [ ]   -  matches any of the characters included between the brackets matches a single character 
* as Wild Card:* matches zero or more characters:-
  • *.txt -  Files those ends with .txt 
  • a*  -  Files those start with a
  • a*.txt -  Files those start with a and end with .txt
ls *.txt
ls a*
ls a*.txt

  ? as Wild Card:
?  matches exactly one character:- 
  • ?  -   Files those have one character
  •  ?.txt -  Files those have one character and ends with .txt 
  •  a?.txt  -  Files those start with a and have one more character and end with .txt
ls ?
ls ?.txt
ls ??.txt
ls a?.txt

[] as Wild Card:
    [] matches any of the characters included between the brackets match a single character
  • ca[nt]*  -  Files start with ca and have n or t in it and have more character after n or t like – cat, can, candy, catch etc.  
  •  [!]  -  Exclude any character  ex:-   [!abc]  -  Files start with a, b, c will be excluded
la ca[nt]*
ls *.txt
ls [!ae]*.txt
Wild Card – Range:
   Use two character separated by a hyphen to create a range in character class
  • [a-e]  -  Matches all files start with a, b, c, d or  
  •  [1-4]  -  Matches all files start with 1, 2, 3 or 4
ls *.txt
ls [a-e]*.txt
Matching Wild Card Patterns:
\   -  Escape character. Use if you want to match a wild card character
  • *\?  -   Matches all files that ends with a question mark 
ls *\?
Nmae Character Classes:   
  •   [[:alpha:]]  -  All alphabatical letters lower and upper case
  •  [[:upper:]]  -  Upper case alphabatics 
  •  [[:lower:]]  -  Lower case alphabatics 
  •  [[:alnum:]]  -  Alphabatical letters (lower and upper case) and Digit 
  •  [[::digit:]]  -  Only digit
  • [[:space:]]  -  Such as spaces, tab, new line characters
ls *[[:upper:]].txt
ls *[[:digit:]].txt
ls *[[:digit:]]*

Wlid Cards in Linux Wlid Cards in Linux Reviewed by vijay pratap singh on March 26, 2017 Rating: 5

No comments:

Powered by Blogger.