LX0-103 · Question #16
What command will generate a list of user names from /etc/passwd along with their login shell?
The correct answer is D. cut -d: -f1,7 /etc/passwd. The cut command with -d: sets the colon delimiter used in /etc/passwd, and -f1,7 selects field 1 (username) and field 7 (login shell).
Question
What command will generate a list of user names from /etc/passwd along with their login shell?
Options
- Acolumn -s : 1,7 /etc/passwd
- Bchop -c 1,7 /etc/passwd
- Ccolrm 1,7 /etc/passwd
- Dcut -d: -f1,7 /etc/passwd
How the community answered
(50 responses)- A2% (1)
- B2% (1)
- C4% (2)
- D92% (46)
Why each option
The cut command with -d: sets the colon delimiter used in /etc/passwd, and -f1,7 selects field 1 (username) and field 7 (login shell).
The column command formats whitespace- or delimiter-separated input into aligned columns for display purposes and does not support extracting specific numbered fields with the syntax shown.
chop is not a standard command in Linux distributions and does not exist as a utility for field extraction from text files.
colrm removes characters by absolute column (character) position rather than by logical field number in a delimiter-separated file, making it unsuitable for extracting colon-delimited fields.
The /etc/passwd file stores records as colon-delimited fields where field 1 is the username and field 7 is the login shell. The cut command's -d: option sets the input field delimiter to a colon, and -f1,7 instructs cut to extract and print only those two fields for each line, producing a concise list of usernames paired with their assigned login shells.
Concept tested: cut command field extraction from colon-delimited /etc/passwd
Source: https://www.gnu.org/software/coreutils/manual/html_node/cut-invocation.html
Topics
Community Discussion
No community discussion yet for this question.