XK0-004 · Question #218
A junior Linux administrator needs to create 16 empty files quickly that will contain sales information for each quarter for the past four years. Which of the following commands will meet this…
The correct answer is A. touch {2015,2016,2017,2018}.{q1,q2,q3,q4}. Bash brace expansion with comma-separated values inside curly braces generates all combinations of the listed tokens. Using the syntax {a,b}.{c,d} creates a Cartesian product of the two lists as filenames passed to touch.
Question
A junior Linux administrator needs to create 16 empty files quickly that will contain sales information for each quarter for the past four years. Which of the following commands will meet this requirement?
Options
- Atouch {2015,2016,2017,2018}.{q1,q2,q3,q4}
- Btouch [2015,2016,2017,2018].[q1,q2,q3,q4]
- Ctouch
2015,2016,2017,2018.q1,q2,q3,q4 - Dtouch {2015.2016.2017.2018}.{q1.q2.q3.q4}
How the community answered
(57 responses)- A79% (45)
- B11% (6)
- C7% (4)
- D4% (2)
Why each option
Bash brace expansion with comma-separated values inside curly braces generates all combinations of the listed tokens. Using the syntax {a,b}.{c,d} creates a Cartesian product of the two lists as filenames passed to touch.
Bash brace expansion with comma-separated values - such as {2015,2016,2017,2018}.{q1,q2,q3,q4} - generates all 16 combinations (e.g., 2015.q1, 2015.q2, ... 2018.q4), and 'touch' creates an empty file for each one. This is the correct syntax for producing a Cartesian product of named values in bash.
Square brackets in shell globbing define character classes or ranges (e.g., [a-z]), not comma-separated lists for Cartesian expansion, so this syntax would not produce 16 distinct files.
Backticks are used for command substitution - they execute a command and return its output - not for brace-style list expansion, so this syntax would fail or produce unexpected results.
Brace expansion requires comma-separated values inside curly braces; using periods as separators inside braces treats the entire string as a single literal token rather than expanding into separate values.
Concept tested: Bash brace expansion for bulk file creation
Source: https://www.gnu.org/software/bash/manual/bash.html#Brace-Expansion
Topics
Community Discussion
No community discussion yet for this question.