This is the second part of the series. You can review the first part here.
You can use the following awk
command, to list only the usernames, without additional information:
$ awk -F':' '{ print $1}' /etc/passwd
Or, you can use the cut
command:
$ cut -d: -f1 /etc/passwd
Use the getent
command to get a list of all users:
## similar output as for $ cat /etc/passwd command ## $ getent passwd ## get a specific user - desiredUser ## $ getent passwd | grep desiredUser ## get a list of all users ## $ getent passwd | cut -d: -f1 ## count all user accounts using the wc ## $ getent passwd | wc -l
You can use the compgen
command with the -u
option, to list only the user names:
$ compgen -u
If you want to learn more, read also the third part of this tutorial.