Bird
Raised Fist0
Linux CLIscripting~5 mins

File globbing (wildcards *, ?, []) in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What does the wildcard * mean in file globbing?
The * wildcard matches zero or more characters in file names. For example, *.txt matches all files ending with .txt.
Click to reveal answer
beginner
How does the ? wildcard work in file globbing?
The ? wildcard matches exactly one character. For example, file?.txt matches file1.txt or fileA.txt but not file12.txt.
Click to reveal answer
beginner
What is the purpose of square brackets [] in file globbing?
Square brackets [] match any one character inside them. For example, file[123].txt matches file1.txt, file2.txt, or file3.txt.
Click to reveal answer
beginner
How would you match all files starting with 'data' and ending with '.csv' using globbing?
Use the pattern data*.csv. The * matches any characters between 'data' and '.csv'.
Click to reveal answer
intermediate
What does the pattern file[!a-c].txt match?
It matches files named file followed by any single character except 'a', 'b', or 'c', then .txt. For example, filed.txt matches but filea.txt does not.
Click to reveal answer
Which wildcard matches exactly one character?
A?
B{}
C[]
D*
What does the pattern *.sh match?
AAll files ending with .sh
BAll files starting with .sh
CFiles with exactly 3 characters
DFiles named * or .sh
How do you match files named file1.txt, file2.txt, or file3.txt but not file4.txt?
Afile?.txt
Bfile[123].txt
Cfile*.txt
Dfile[!123].txt
What does the pattern file[!a-c].txt do?
AMatches files starting with filea-c
BMatches files with a, b, or c after file
CMatches files without a, b, or c after file
DMatches files ending with a-c.txt
Which pattern matches all files starting with 'log' and ending with any single character?
Alog*
Blog[?]
Clog[]
Dlog?
Explain how the wildcards *, ?, and [] work in file globbing with examples.
Think about how you find files by patterns in a folder.
You got /4 concepts.
    Describe how to exclude certain characters using file globbing patterns.
    It's like saying 'match anything except these letters'.
    You got /3 concepts.

      Practice

      (1/5)
      1. Which wildcard pattern matches all files with any extension starting with log in their name?
      easy
      A. log* only matches files named exactly 'log'
      B. log?
      C. log[0-9]
      D. log*

      Solution

      1. Step 1: Understand the wildcard *

        The * matches zero or more characters, so log* matches any file starting with 'log' followed by anything or nothing.
      2. Step 2: Compare other options

        log? matches 'log' plus exactly one character, log[0-9] matches 'log' plus one digit, and the last option is incorrect about log*.
      3. Final Answer:

        log* -> Option D
      4. Quick Check:

        Wildcard * matches any characters [OK]
      Hint: Use * to match any number of characters [OK]
      Common Mistakes:
      • Confusing * with ? wildcard
      • Thinking * matches only one character
      • Misunderstanding [] as matching multiple characters
      2. Which of the following is the correct pattern to match files named data1, data2, but not data10?
      easy
      A. data?
      B. data*
      C. data[1-9]
      D. data??

      Solution

      1. Step 1: Understand the pattern data[1-9]

        This matches 'data' followed by exactly one digit from 1 to 9, so it matches 'data1' and 'data2' but not 'data10'.
      2. Step 2: Check other patterns

        data? matches 'data' plus any one character (including letters), data* matches 'data' plus any characters (including 'data10'), and data?? matches 'data' plus exactly two characters (so it matches 'data10').
      3. Final Answer:

        data[1-9] -> Option C
      4. Quick Check:

        Square brackets match one character from set [OK]
      Hint: Use [ ] to match one character from a range [OK]
      Common Mistakes:
      • Using * which matches too many files
      • Using ? which matches any single character, not range
      • Confusing number of characters matched
      3. Given files: file1.txt, file2.txt, fileA.txt, fileB.txt, what files does the pattern file?.txt match?
      medium
      A. file1.txt, file2.txt
      B. file1.txt, file2.txt, fileA.txt, fileB.txt
      C. fileA.txt, fileB.txt
      D. file.txt

      Solution

      1. Step 1: Understand the pattern file?.txt

        The ? matches exactly one character, so it matches any file named 'file' plus one character plus '.txt'.
      2. Step 2: Check which files match

        All files with names 'file1.txt', 'file2.txt', 'fileA.txt', and 'fileB.txt' have exactly one character after 'file' before '.txt', so all match.
      3. Final Answer:

        file1.txt, file2.txt, fileA.txt, fileB.txt -> Option B
      4. Quick Check:

        ? matches exactly one character [OK]
      Hint: Use ? to match exactly one character [OK]
      Common Mistakes:
      • Thinking ? matches zero or multiple characters
      • Confusing ? with *
      • Ignoring file extension in pattern
      4. You want to list files named report1, report2, and report3 only. Which pattern is incorrect?
      medium
      A. report*
      B. report?
      C. report[1-3]
      D. report[123]

      Solution

      1. Step 1: Analyze pattern report*

        This matches 'report' plus any characters, so it matches more than just 'report1', 'report2', and 'report3'. It includes 'report10', 'report_final', etc.
      2. Step 2: Check other patterns

        report[1-3] and report[123] match exactly one character from 1,2,3 after 'report'. report? matches 'report' plus any one character, which includes 'report1', 'report2', 'report3' but also others with one character.
      3. Final Answer:

        report* -> Option A
      4. Quick Check:

        * matches too many files [OK]
      Hint: Use [] to limit characters, * matches too many [OK]
      Common Mistakes:
      • Using * when exact matches needed
      • Assuming ? limits to digits only
      • Not realizing [] matches one character only
      5. You have files: img01.png, img02.png, img10.png, img20.png. Which pattern matches only files with numbers from 01 to 09?
      hard
      A. img0[1-9].png
      B. img[0-9][1-9].png
      C. img??.png
      D. img[01-09].png

      Solution

      1. Step 1: Understand pattern img0[1-9].png

        This matches 'img0' plus one digit from 1 to 9, then '.png'. So it matches 'img01.png' to 'img09.png'.
      2. Step 2: Check other patterns

        img[0-9][1-9].png matches any two digits, including 'img10.png' and 'img20.png'. img??.png matches any two characters after 'img', so all files. img[01-09].png is invalid syntax because ranges like '01-09' are not valid inside [].
      3. Final Answer:

        img0[1-9].png -> Option A
      4. Quick Check:

        Use 0 then [1-9] for numbers 01-09 [OK]
      Hint: Use fixed digit then range in [] for number ranges [OK]
      Common Mistakes:
      • Using invalid range syntax inside []
      • Using ?? which matches any two characters
      • Not fixing leading zero for 01-09
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard