File globbing is a feature provided by the UNIX/Linux shell to represent multiple filenames by using special characters called wildcards with a single file name. A wildcard is essentially a symbol which may be used to substitute for one or more characters. Therefore, we can use wildcards for generating the appropriate combination of file names as per our requirement.
Examples using other wildcard characters :
1) arterisk (*)* is used to match any number of characters(zero or more), to understand more you can refer the example taken above.
-l *.pl
this will show all the files that end with .pl
2) question mark(?)? is used to match exactly one character.
ls -l ????.txt will show all the files that are four characters long and have a .txt extention
test.txt rest.txt broo.txt foob.txt
ls -l foot????.doc
will show football.doc for example
3) Square Brackets [ ]Square brackets are used to match the characters inside [ ],[ ] can be used to match exact characters or you can also specify a range, using ‘hello[1-5]’ will display all files and directories starting with ‘hello’, then the next character can be a numbers from 1 to 5.
All uppercase alphabets are defined by the range as, [:upper:] or [A-Z] .
All lowercase alphabets are defined by the range as, [:lower:] or [a-z].
All numeric digits are defined by the range as, [:digit:] or [0-9].
All uppercase and lower alphabets are defined by the range as, [:alpha:] or [a-zA-z].
All uppercase alphabets, lowercase alphabet and digits are defined by the range as, [:alnum:] or [a-zA-Z0-9]
Examples:
Run the following command to search all files and folders whose name contains p or q or r or s.
$ ls -l [p-s]*
Run the following command to search all files and folders whose name starts with any digit from 1 to 5.
$ ls -l [1-5]*
globbing is usually used with ls and rm commands to either show files based on a pattern or remove files based on a pattern.
and globbing follows regular expression patterns.