wildcard is a symbol used to replace or represent one or more characters. They are used to find the file and directory names which increases the flexibility and efficiency of searches.
- *Â Â :-Â Asterisk symbol is used to represent any character(s).
- ? :- Question mark represents any single character.
- []Â :-Â Square brackets represents a range of characters.
How to use :-
* (Asterisk) Wildcard :-
-> $ ls .txt  :- This would list all the files having .txt extension .
-> $ ls *mom :- This would list all the files that have the letters “mom” anywhere in their filenames.
-> $Â ls a*Â :- This would list all the files starting with letter a.
-> $ ls *z :- This would list all the files ending with letter z.
? (Question Mark) Wildcard
-> $ ls file? :- This would list all the files that begin with “file” and have one more valid character.(file?.txt for files having extension as txt)
-> $ ls ?i* :- This would list all the files whose second letter is i .
-> $ ls *.??? :- This would list all the files having three letter extension.
[] (Square Brackets) Wildcard
-> $ ls [fg]Â :- This would list every file whose name either begins with a f or g.
-> $ ls [p-s]Â :– This would list all files that start with “p,q,r or s”.
-> $ ls a[p-s] :- This would list all files start with the letter “a” and second letter contains “p,q,r or s”.
-> $ ls [a-c,A-C] :- This would list all files start with the letter “a,b,c,A,B,C”. The [ , ] imply that this entire range indicates ONLY ONE letter which can be from any of the two given sub-ranges.
-> $ ls .[tx]Â :-
This would list all the files that have extension that begins with t or x.
-> $ ls [!a-c]Â :- This would list all files except those that start with “a, b or c”.
You must be logged in to post a comment.