File globbing in Linux

Before we move to file globbing, let’s understand what are wildcard patterns, these are the patterns containing strings like ‘?’, ‘*’

File globbing is the operation that recognises these patterns and does the job of file path expansion.

See the below example for clear understanding,

path expansion for ‘*’

If you observe the image above, I created several directories whose starting characters are HELLO and hello, and then tried to delete these directories.

When I used rm -rf hello*, it deleted the directories hello1, hello2, hello3, the ‘*’ symbol used after ‘hello’ recognises the first characters as ‘hello’ and then zero or more occurrences of any other characters.

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.

2) question mark(?)
? is used to match exactly one character.

In above image, you can observe that ‘?’ can match exactly one character and is used at the end of the line.
So using ‘hello?’ will match all files or directories whose starting characters are ‘hello’ and it will recognise one more character.

3) Square Brackets []
Square brackets are used to match the characters inside [], refer below image,

[] can be used to match exact characters or you can also specify a range, like in above example, using ‘hello[1-5]’ will display all files and directories staring with ‘hello’, then the next character can be a numbers from 1 to 5.

4) exclamation mark (!)
! is used to exclude characters from list that is specified within the square brackets.

For example:

ls hello[!3]

It will display the directories starting with hello, ending with any character but not 3

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :


Please write to us at to report any issue with the above content.