- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
File globbing in Linux in C++
p>File globbing also known as Path Name Expansion. It is the method of recognizing wildcard patterns in linux and then finding the file path expansion based on these patterns.
Wildcard Patterns are strings that are used for selection of multiple files based on patterns.
The character patterns like “?” , “[ ]” , “*” are used for pattern matching and multiselection of the files.
Example of wildcard characters using in file globbing:
- Asterisk (*) : the * pattern is used when we need to match 0 or more character after the string in the filename.
For example: file* will match all files with name file, files, file2, or with anything after file.
- Question Mark (?): The ? pattern is used when we need to match exactly one character after the string in the filename.
For example: file* will match filename file1, but not file01 or file.
- Square Brackets (): The  pattern is used when we need to match a specific number of characters after the string in the filename. It square brackets you can mention number as well as range for matching.
For example: file will match all filenames with exactly 2 more characters at the end like file01 but not file1 or file211.
File[1- 3] will match all filenames with 1, 2 or 3 more characters at the end. Like file1, file01, file211 but not more than that.
One more additional thing that can be inside the brackets is the negation of a specific count, it is done using ! or exclamation mark, this excludes the count instead of the specific number of characters.
For example: file[!2] will match all file names which have extra characters elser than 2. Like file1, file211 but not file01.
Here is how to implement these in linux commands −
We have created some files in a folder −
file , file1, file01, file211, files.
Then used all globbing patterns on it. Here is the result −
- How to sort a file in-place in Linux?
- How to Copy File Permissions and Ownership to Another File in Linux?
- How to Save Command Output to a File in Linux?
- How to Copy a File to Multiple Directories in Linux?
- How to Create a New Ext4 File System in Linux?
- How to change the file owner and group in Linux?
- How to change file or directory permission in Linux/Unix?
- How to Create a New File in Linux from Bash?
- Display Command Output or File Contents in Column Format in Linux
- Text and File processing using sed Linux Commands
- How to disable delete permission of File and Directory in Linux?
- How to Empty or Delete a Large File Content in Linux?
- How to flushes file system buffers in the Linux operating system?
- How to removes duplicate lines from a sorted file in Linux?
- How to overwrite a file to hide file contents, and make original contents unrecoverable in Linux?