System Management

An administrator needs a list of the account names in /etc/passwd whose login shell is /bin/bash. The file is colon-delimited, with the username in field 1 and the shell in field 7, and the output must contain only the usernames. Which command produces this output?

Show the answer

Correct answerA. awk -F: '$7 == "/bin/bash" {print $1}' /etc/passwd

awk -F: sets the colon as the field separator, so the test on field 7 selects the bash users and print $1 outputs only their names. Without -F:, awk splits on whitespace, so $7 is empty and nothing matches. The cut and grep pipeline would also print the shell, not just the names.