Can you give more globbing examples?

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 not file.txt or file123.txt.

3. Bracket Expression ([])

  • Pattern: file[1-3].txt
  • Matches: Any character within the brackets.
  • Example: file1.txt, file2.txt, file3.txt, but not file4.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 not file1.txt, file2.txt, or file3.txt.

5. Double Asterisk (**)

  • Pattern: **/*.txt
  • Matches: All .txt files in the current directory and all subdirectories (requires shopt -s globstar in Bash).
  • Example: If you have dir1/file.txt and dir2/dir3/file.txt, both will be matched.

6. Specific Prefix or Suffix

  • Pattern: prefix* or *suffix
  • Matches: Files that start with prefix or end with suffix.
  • Example: prefix_file.txt or file_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 not file4.txt or fileA.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!

0 Comments

no data
Be the first to share your comment!