Certainly! Here are some common examples of shell globbing patterns and what they match:
1. Asterisk (*)
- Pattern:
* - Matches: Any string, including an empty string.
- Example:
ls *lists all files and directories in the current directory.
2. Question Mark (?)
- Pattern:
file?.txt - Matches: Any single character in place of the question mark.
- Example:
file1.txt,fileA.txt, but notfile.txtorfile123.txt.
3. Bracket Expression ([])
- Pattern:
file[1-3].txt - Matches: Any character within the brackets.
- Example:
file1.txt,file2.txt,file3.txt, but notfile4.txt.
4. Negation in Bracket Expression (!)
- Pattern:
file[!1-3].txt - Matches: Any character not in the specified range.
- Example:
file4.txt,fileA.txt, but notfile1.txt,file2.txt, orfile3.txt.
5. Double Asterisk (**)
- Pattern:
**/*.txt - Matches: All
.txtfiles in the current directory and all subdirectories (requiresshopt -s globstarin Bash). - Example: If you have
dir1/file.txtanddir2/dir3/file.txt, both will be matched.
6. Specific Prefix or Suffix
- Pattern:
prefix*or*suffix - Matches: Files that start with
prefixor end withsuffix. - Example:
prefix_file.txtorfile_suffix.txt.
7. Combination
- Pattern:
file[1-3]*.txt - Matches: Files that start with
file, followed by a digit from 1 to 3, and end with.txt. - Example:
file1.txt,file2_data.txt, but notfile4.txtorfileA.txt.
These examples illustrate how globbing can be used to match files and directories based on patterns. If you have any specific scenarios in mind or further questions, feel free to ask!
