LFCS · Question #829
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 can extract specific fields from a delimited file like /etc/passwd, where fields are separated by a colon, to list usernames and their login shells.
Question
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
(47 responses)- A4% (2)
- B6% (3)
- C2% (1)
- D87% (41)
Why each option
The `cut` command can extract specific fields from a delimited file like `/etc/passwd`, where fields are separated by a colon, to list usernames and their login shells.
`column` is used to format data into columns and does not have `-s` or direct field selection options like `1,7` for extraction in this manner.
`chop` is not a standard Linux command for text processing like this; similar functionality might be found in `cut` or `awk`.
`colrm` is used to remove columns from a file based on character positions, not delimited fields, and its syntax `1,7` would mean removing characters from position 1 to 7.
The `cut` command with the `-d:` option specifies a colon as the delimiter, and `-f1,7` selects the first field (username) and the seventh field (login shell) from each line of `/etc/passwd`. This effectively extracts the desired information.
Concept tested: Extracting fields from delimited files
Source: https://man7.org/linux/man-pages/man1/cut.1.html
Topics
Community Discussion
No community discussion yet for this question.