The directory contains log1.txt, logA.txt, and log10.txt.
Pass only names with exactly one character after log and before .txt to ls.
Which filename pattern is appropriate?
In shell globbing, ? matches exactly one character. * matches zero or more characters and is broader.
Detailed explanation
log?.txtCorrect. log?.txt matches log1.txt and logA.txt but not log10.txt.
Correct. log?.txt matches log1.txt and logA.txt but not log10.txt.
log*.txtIncorrect. * can match zero or more characters, including the two digits in log10.txt.
Incorrect. * can match zero or more characters, including the two digits in log10.txt.
log[0-9].txtIncorrect. [0-9] limits the character to a digit and excludes logA.txt.
Incorrect. [0-9] limits the character to a digit and excludes logA.txt.
log??.txtIncorrect. ?? requires two characters.
Incorrect. ?? requires two characters.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); touch "$tmp/log1.txt" "$tmp/logA.txt" "$tmp/log10.txt"; (cd "$tmp" && printf '%s\n' log?.txt); rm -rf "$tmp"Expected result
log1.txt
logA.txtKey points
- ? matches one character
- * matches zero or more
- The shell expands globs
Notes
- Environment: Bash 5.x / 一時ディレクトリ
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.