Menu
Coddy logo textTech

The Question Mark Wildcard

Part of the Fundamentals section of Coddy's Terminal journey — lesson 26 of 82.

The question mark wildcard ? matches exactly one character. Unlike * which matches any number of characters, ? is more precise — each ? represents a single character position.

For example, if you have these files:

file1.txt
file2.txt
file3.txt
file10.txt
notes.txt

Using ? to match files with exactly one character after file:

ls file?.txt

Output:

file1.txt
file2.txt
file3.txt

Notice that file10.txt is not matched because 10 is two characters, not one.

Using multiple question marks:

Each ? matches exactly one character, so you can chain them:

ls file??.txt   # matches file10.txt, file23.txt etc.

Mixing with other characters:

ls ???.txt      # matches any .txt file with exactly 3-character name
ls img_?.jpg    # matches img_1.jpg, img_2.jpg but NOT img_10.jpg

When to use ? vs *:

  • Use ? when you know exactly how many characters vary
  • Use * when the number of varying characters is unknown
challenge icon

Challenge

Beginner

Use the ? wildcard to list only the files that match file?.txt — files named file followed by exactly one character and ending with .txt.

Hint: file10.txt should not appear in your results because 10 is two characters. The ? wildcard matches only one character at a time.

Cheat sheet

The question mark wildcard ? matches exactly one character. Unlike * which matches any number of characters, ? is more precise — each ? represents a single character position.

Example matching files with exactly one character after file:

ls file?.txt

Using multiple question marks:

Chain multiple ? to match multiple characters:

ls file??.txt   # matches file10.txt, file23.txt etc.

Mixing with other characters:

ls ???.txt      # matches any .txt file with exactly 3-character name
ls img_?.jpg    # matches img_1.jpg, img_2.jpg but NOT img_10.jpg

When to use ? vs *:

  • Use ? when you know exactly how many characters vary
  • Use * when the number of varying characters is unknown

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals