nerdexam
LPI

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.

Finding Your Way on a Linux System

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)
  • A
    77% (43)
  • B
    5% (3)
  • C
    4% (2)
  • D
    2% (1)
  • E
    13% (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.

Als [A-Z]*Correct

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.

Bls A-Z

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.

Cls 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.

Dls --uppercasefiles

--uppercasefiles is not a valid ls option; ls will return an error for this unrecognized flag.

Elist-uppercase-files

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

#ls command#glob patterns#wildcards#file listing

Community Discussion

No community discussion yet for this question.

Full 010-100 Practice