nerdexam
LPI

010-100 · Question #28

Which of the following is an example of globbing?

The correct answer is C. ls /etc/*.txt. Globbing refers to the shell's wildcard pattern-matching expansion applied to filenames, and using '*.txt' is a classic example of a glob pattern.

The Power of the Command Line

Question

Which of the following is an example of globbing?

Options

  • Als /etc/ 2> files.txt
  • Bls /etc/ > files.txt
  • Cls /etc/*.txt
  • Dls /etc/ | more

How the community answered

(26 responses)
  • A
    4% (1)
  • B
    15% (4)
  • C
    69% (18)
  • D
    12% (3)

Why each option

Globbing refers to the shell's wildcard pattern-matching expansion applied to filenames, and using '*.txt' is a classic example of a glob pattern.

Als /etc/ 2> files.txt

The '2>' operator redirects stderr (file descriptor 2) to a file, which is an example of I/O redirection, not globbing.

Bls /etc/ > files.txt

The '>' operator redirects stdout to a file, which is standard output redirection, not a glob pattern.

Cls /etc/*.txtCorrect

The expression 'ls /etc/*.txt' uses the '*' wildcard, which the shell expands to match any filename ending in '.txt' within /etc/ before passing the results to ls. This pattern-matching mechanism is called globbing and is handled entirely by the shell, not by the command itself.

Dls /etc/ | more

The '|' character is a pipe that passes stdout of one command as stdin to another, which is inter-process communication, not globbing.

Concept tested: Shell globbing and wildcard filename expansion

Source: https://www.gnu.org/software/bash/manual/bash.html#Filename-Expansion

Topics

#globbing#wildcards#filename expansion#shell patterns

Community Discussion

No community discussion yet for this question.

Full 010-100 Practice