Wild cards * [] ?

 Wild card Characters



An asterisk (*)
------->> matches one or more occurrences of any character, including no character.


Question mark (?) 
-------->> represents or matches a single occurrence of any character.


Bracketed characters ([ ])
 --------->> matches any occurrence of character enclosed in the square brackets.



Examples


[haritaraka12078@cxln4 ~]$ ls jun*
Output-------->>jun1  jun2  jun3  jun4  jun5
Note-------->>matches all files& directories with names start with jun



[haritaraka12078@cxln4 ~]$ ls *.txt
Output-------->>file.txt
Note-------->> matches all files with names end with extension .txt



[haritaraka12078@cxln4 ~]$ ls *5
Output-------->>abc5  jun5   dir5:
Note-------->> matches all files& directories with names end with 5



[haritaraka12078@cxln4 ~]$ ls ????
Output -------->>abc5  jun1  jun2  jun3  jun4  jun5  tee4
Note-------->> It will show the 4 charters files only



[haritaraka12078@cxln4 ~]$ touch {a..j} b{1..5}
Note-------->> It will create the files (a to j) and (b1 to b5)



[haritaraka12078@cxln4 ~]$rm {a..j} b{1..5}
Note -------->>It will remove the files (a to j) and (b1 to b5)



[haritaraka12078@cxln4 ~]$ ls l?st.sh
Output -------->>list.sh  lost.sh
Note -------->> matches all files with names beginning with l followed by any single character and ending with st.sh (which is the suffix).




[haritaraka12078@cxln4 ~]$ ls l[abdcio]st.sh
Note-------->> matches all files with names starting with l followed by any of the characters in the square bracket but ending with st.sh.




[haritaraka12078@cxln4 ~]$ ls ??le*
Output -------->> file1  file1,file2,file3  file2  file3  file7  file-list  file.txt
Note -------->> all filenames prefixed with any two characters followed by 'le' but ending with one or more occurrence of any character.


 
 
 [haritaraka12078@cxln4 ~]$ ls [fjt]*
Output -------->> f  file1  file1,file2,file3  file2  file3  file7  file-list  file.txt  j  jun1  jun2  jun3  jun4  jun5  tee4
Note-------->> matches filenames starting with any of these characters [fjt] and ending with one or more occurrence of any character.




[haritaraka12078@cxln4 ~]$ ls [fjt][ee]?4*
Output -------->>tee4
Note-------->> only filenames starting with any of these characters [fjt] followed by one of these [ee] and then any single character, 
followed by a 4 and lastly, one or more occurrence of any character will be listed.



$ ls users-[0-9][!0-9][a-zA-Z]* 
-------->> Negate a Set of Characters in Linux (! symbol)



$ ls users-[0-9][a-z0-9][0-9]*
-------->> match all files whose name starts with users-i, followed by a number, a lower case letter or number, then a number and ends with one or more occurrences of any character.



$ ls users-[0-9][a-zA-Z0-9][0-9]*
-------->>matches filenames beginning with users-i, followed by a number, a lower or upper case letter or number, then a number and ends with one or more occurrences of any character.



$ ls users-[0-9][a-zA-Z0-9][a-zA-Z]*
-------->>users-i, followed by a number, a lower or upper case letter or number, then a lower or upper case letter and ends with one or more occurrences of any character.