010-100 · Question #71
Which command lists all files in the current directory that start with a capital letter?
The correct answer is A. ls [A-Z]*. Shell glob bracket expressions like [A-Z] match a single character in the specified range, and appending * matches any remaining characters, selecting all files starting with a capital letter.
Question
Which command lists all files in the current directory that start with a capital letter?
Options
- Als [A-Z]*
- Bls A-Z
- Cls A-Z*
- Dls --uppercasefiles
- Elist-uppercase-files
How the community answered
(56 responses)- A77% (43)
- B5% (3)
- C4% (2)
- D2% (1)
- E13% (7)
Why each option
Shell glob bracket expressions like [A-Z] match a single character in the specified range, and appending * matches any remaining characters, selecting all files starting with a capital letter.
The glob pattern [A-Z]* uses a bracket expression to match any single uppercase letter A through Z as the first character, followed by * which matches zero or more of any characters. The shell expands this pattern before passing arguments to ls, listing all files in the current directory whose names begin with a capital letter.
ls A-Z is interpreted as a literal filename argument named A-Z, not a range, so ls will look for a file or directory literally called A-Z.
ls A-Z* treats A-Z as a literal prefix and * as a wildcard after it, matching files whose names literally start with the string A-Z, not files starting with any uppercase letter.
--uppercasefiles is not a valid ls option; ls will return an error for this unrecognized flag.
list-uppercase-files is not a valid Linux command and will result in a command not found error.
Concept tested: Shell glob bracket expressions for filename matching
Source: https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching
Topics
Community Discussion
No community discussion yet for this question.