nerdexam
CompTIA

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).

GNU and Unix Commands

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)
  • A
    2% (1)
  • B
    2% (1)
  • C
    4% (2)
  • D
    92% (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).

Acolumn -s : 1,7 /etc/passwd

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.

Bchop -c 1,7 /etc/passwd

chop is not a standard command in Linux distributions and does not exist as a utility for field extraction from text files.

Ccolrm 1,7 /etc/passwd

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.

Dcut -d: -f1,7 /etc/passwdCorrect

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

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

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice