How can I list all users along with their UIDs? I want to do this from the terminal.
5 Answers
List all users with a /home
folder:
awk -F: '/\/home/ {printf "%s:%s\n",$1,$3}' /etc/passwd
or all users with a UID >= 1000
:
awk -F: '($3 >= 1000) {printf "%s:%s\n",$1,$3}' /etc/passwd
a combination
awk -F: '/\/home/ && ($3 >= 1000) {printf "%s:%s\n",$1,$3}' /etc/passwd
or for all entries
awk -F: '{printf "%s:%s\n",$1,$3}' /etc/passwd
More information here
You can find it easily by just using cut
:
cut -d: -f1,3 /etc/passwd
-d:
sets the delimiter as:
forcut
-f1,3
extracts the field 1 and 3 only delimited by:
from the/etc/passwd
file
Check man cut
to get more idea.
Example :
$ cut -d: -f1,3 /etc/passwd
root:0
daemon:1
bin:2
sys:3
sync:4
games:5
......
If you have ldap
configured, to include the ldap
users in the output :
getent passwd | cut -d: -f1,3
-
1You should use
getent passwd
instead of /etc/passwd since the latter won't include ldap users– DaenythJul 6, 2015 at 23:16 -
@Daenyth My initial answer was that actually..then for the sake of simplification (and considering no
ldap
) i have moved to teh current one..anyway edited :)– heemaylJul 6, 2015 at 23:25
Alternatively to list all users including UID and GID information.
for user in $(cat /etc/passwd | cut -f1 -d":"); do id $user; done
Cheers,
Because you are trying to list the UID and Username, the below command works better best on Solaris. They have two awk
awk -F: '($3 >=1000) {printf "%s:%s",$1,$3}' /etc/passwd
I find the easiest way is to have webmin on your server and simply go to System > Users and Groups and there you have a nicely formatted list with all usernames & groups with their uid's, home directory etc.