What command will generate a list of user names from /etc/passwd along with their login shell?
Click on the arrows to vote for the correct answer
A. B. C. D.D
The correct answer is D. cut -d: -f1,7 /etc/passwd.
Explanation: The file /etc/passwd contains user account information on a Linux system, including the login shell for each user. To generate a list of user names from /etc/passwd along with their login shell, we can use the cut
command.
The cut
command is used to extract specific columns from a file. In this case, we want to extract the first and seventh columns from /etc/passwd. We can specify the delimiter between columns using the -d
option. In this case, the delimiter is a colon (:). We can specify the columns we want to extract using the -f
option.
So, the correct command to generate a list of user names from /etc/passwd along with their login shell is:
bashcut -d: -f1,7 /etc/passwd
This will output a list of user names followed by their login shell, separated by a colon (:). For example:
javascriptroot:/bin/bash daemon:/usr/sbin/nologin bin:/usr/sbin/nologin sys:/usr/sbin/nologin ...
Option A (column -s : 1,7 /etc/passwd) would generate output in tabular format, but it would not separate the user names and login shells with a colon (:), as required.
Option B (chop -c 1,7 /etc/passwd) and option C (colrm 1,7 /etc/passwd) are not valid commands and would result in an error.