nerdexam
CompTIA

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.

GNU and Unix Commands

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)
  • A
    2% (1)
  • B
    5% (3)
  • C
    88% (58)
  • D
    6% (4)

Why each option

The cut command extracts specific fields from delimited text, making it the correct tool for parsing columns from /etc/passwd.

Afmt -f 1,4 /etc/passwd

fmt is a text formatting utility used to reformat paragraph text and does not support field selection with a -f flag.

Bsplit -c 1,4 /etc/passwd

split divides files into smaller pieces based on line count or byte size and does not support column extraction.

Ccut -d : -f 1,4 /etc/passwdCorrect

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.

Dpaste -f 1,4 /etc/passwd

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

#cut#field delimiter#/etc/passwd#text processing

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice