nerdexam
LPI

101-500 · Question #506

Which wildcards will match the following filenames? (Choose two.) ttyS0 ttyS1 ttyS2

The correct answer is B. tty?[0-5] D. tty[A-Z][012]. You've hit your Sonnet limit · resets Jun 8, 9am (UTC)

Shells and Shell Scripting

Question

Which wildcards will match the following filenames? (Choose two.) ttyS0 ttyS1 ttyS2

Options

  • AttyS[1-5]
  • Btty?[0-5]
  • Ctty*2
  • Dtty[A-Z][012]
  • Etty[Ss][02]

How the community answered

(58 responses)
  • A
    3% (2)
  • B
    81% (47)
  • C
    10% (6)
  • E
    5% (3)

Explanation

You've hit your Sonnet limit · resets Jun 8, 9am (UTC)

Topics

#wildcard patterns#shell globbing#file matching#character classes

Community Discussion

5
Samuel O.Samuel O.May 28, 2026

B and D are your answers here. Option B uses a single wildcard character (the question mark) to match exactly one character, so tty? covers ttyS, and then [0-5] is a character class that covers 0, 1, and 2, meaning it matches all three filenames. Option D uses [A-Z] which is a range class that includes S since it is an uppercase letter, and [012] is a class that explicitly lists the digits 0, 1, and 2, so again all three files match. The others fall short for specific reasons: A misses ttyS0 because [1-5] does not include 0, C only ends in 2 so it cannot match ttyS0 or ttyS1 unless the asterisk expands in an unexpected way, and E includes lowercase s in the class but [02] skips 1 entirely.

24
Mei-Ling H.Mei-Ling H.May 29, 2026

Samuel's breakdown is solid, though worth noting the question mark in B matches any single character, so tty? would also match files like ttya or tty1 if they existed, meaning it works here only because the filesystem has exactly those three files and nothing else unexpected starting with tty.

0
Mei-Ling H.Mei-Ling H.May 18, 2026

E looks right but [02] skips ttyS1, so B and D.

1
Thiago A.Thiago A.May 14, 2026

Almost went A, but ttyS0 drops out since 0 is outside 1-5, B and D nail all three.

0
Fatima Z.Fatima Z.Jun 10, 2026

The hook I use is "B and D, Big Deal" because the question mark in B grabs any single character sitting in that S slot and [0-5] covers all three digits, while D uses [A-Z] which locks onto uppercase S perfectly with [012] finishing the job. On my actual exam I almost circled E thinking tty[Ss][02] was slick, then I caught it dead in its tracks because [02] skips the number 1 entirely, ttyS1 gets left out in the cold, and I literally whispered "gotcha" to my monitor and moved on.

-2
Full 101-500 Practice