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.
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)- A4% (1)
- B15% (4)
- C69% (18)
- D12% (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.
The '2>' operator redirects stderr (file descriptor 2) to a file, which is an example of I/O redirection, not globbing.
The '>' operator redirects stdout to a file, which is standard output redirection, not a glob pattern.
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.
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
Community Discussion
No community discussion yet for this question.