List all users on a server

User information is stored in the /etc/passwd file


[username@localhost /]$ awk -F":" '{ print $1 }' /etc/passwd

If you want to print out the user name and UID:

[username@localhost /]$ awk -F":" '{ print $1 "\t\t"$3 }' /etc/passwd | column -t

Here is the break down of how the command works:

awk - a string formatting utility
-F":" - split each line by ':'
A line in the /etc/passwd like the following gets fed into awk:
root:x:0:0:root:/root:/bin/bash
So we want to separate it based on each semicolon.
'{ - start awk language interpreter
awk is its own language it has an large amount of features
print - awk command to print
$1 - print column 1 which is the user name
"\t\t" - print two tabs
$3 - print column 3 which is the UID
}' - end awk language interpreter
/etc/passwd - the file that awk will process
| - send output to the next command
column - the column command formats data so that they are visually aligned
-t - identify columns based on white space.

comments powered by Disqus