Linux and Command-Line Basics

A directory contains six files: a1.txt, a2.txt, a10.txt, b1.txt, c1.txt and a1.csv. Which of the following is the number of files shown when "ls [ab]?.txt" is run in this directory?

  1. A2
  2. B3
  3. C4
Show answer and explanation

Answer: B. 3

Before running a command, the shell expands names containing wildcards into file names (globbing). [ab] matches one character that is either a or b, ? matches exactly one character, and * matches any string of zero or more characters. [ab]?.txt means "a or b, then any one character, then .txt", so it matches the three files a1.txt, a2.txt and b1.txt. a10.txt has two characters after a, c1.txt starts with c, and a1.csv has a different extension, so they do not match.

  • A. [ab] matches one character that is a or b, so b1.txt is included too.
  • B. Correct. The three files are a1.txt, a2.txt and b1.txt.
  • C. ? matches exactly one character, so a10.txt is not included. Reading ? as zero or more characters, like *, would include a10.txt and give 4.
Practice this topic Back to topic

Books on Linux and Command-Line Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Linux and Command-Line Basics questions

  1. After "chmod 754 run.sh" is run on the file run.sh, which of the following is the permission notation shown at the start of the line from "ls -l run.sh"?
  2. touch creates a new file from 666, and mkdir a new directory from 777, with the umask bits removed. Which of the following is the correct pair of permissions when a new file and a new directory are created in a shell whose umask is 027?
  3. The directory d has permissions rwx--x--x (711), and the file f.txt in it has rw-r--r-- (644). A user who is neither the owner nor the superuser runs "ls d" and "cat d/f.txt". Which of the following is the result?
  4. Which of the following correctly describes the sudo command on Linux?
  5. On many Linux systems, "ls -l /usr/bin/passwd" shows "-rwsr-xr-x 1 root root ...". Which of the following is the meaning of the "s" in the owner's execute position?