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,
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.
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.
 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.
ls hello[!3] It will display the directories starting with hello, ending with any character but not 3
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Chatbot Theory Explained !
- Sudo Placement 2 | Course Structure
- How to prepare for AMCAT?
- How to attempt Function Coding Questions?
- Service-Oriented Architecture
- Editors and Its types in System Programming
- Commonly asked questions in Flipkart Interviews
- Commonly Asked Questions in Goldman Sachs Interviews
- Functional Dependency and Attribute Closure
- GATE CS 2016 Syllabus