LX0-103 · Question #42
Which of the following commands prints a list of usernames (first column) and their primary group (fourth column) from the /etc/passwd file?
The correct answer is C. cut -d : -f 1,4 /etc/passwd. The cut command extracts specific fields from delimited text, making it the correct tool for parsing columns from /etc/passwd.
Question
Which of the following commands prints a list of usernames (first column) and their primary group (fourth column) from the /etc/passwd file?
Options
- Afmt -f 1,4 /etc/passwd
- Bsplit -c 1,4 /etc/passwd
- Ccut -d : -f 1,4 /etc/passwd
- Dpaste -f 1,4 /etc/passwd
How the community answered
(66 responses)- A2% (1)
- B5% (3)
- C88% (58)
- D6% (4)
Why each option
The cut command extracts specific fields from delimited text, making it the correct tool for parsing columns from /etc/passwd.
fmt is a text formatting utility used to reformat paragraph text and does not support field selection with a -f flag.
split divides files into smaller pieces based on line count or byte size and does not support column extraction.
The cut command with -d : sets the colon as the field delimiter, matching the format of /etc/passwd. The -f 1,4 option selects fields 1 (username) and 4 (primary GID), printing exactly the two columns requested without loading the entire file structure.
paste merges lines from multiple files side by side and does not support selecting specific fields from a single delimited file.
Concept tested: Extracting delimited fields with cut command
Source: https://man7.org/linux/man-pages/man1/cut.1.html
Topics
Community Discussion
No community discussion yet for this question.