becko Asked: 2015-07-07 12:02:50 +0800 CST2015-07-07 12:02:50 +0800 CST 2015-07-07 12:02:50 +0800 CST Command to list all users with their UID? 772 How can I list all users along with their UIDs? I want to do this from the terminal. command-line 5 Answers Voted Best Answer A.B. 2015-07-07T12:21:39+08:002015-07-07T12:21:39+08:00 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 heemayl 2015-07-07T12:26:25+08:002015-07-07T12:26:25+08:00 You can find it easily by just using cut : cut -d: -f1,3 /etc/passwd -d: sets the delimiter as : for cut -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 Boschko 2019-10-17T15:56:27+08:002019-10-17T15:56:27+08:00 Alternatively to list all users including UID and GID information. for user in $(cat /etc/passwd | cut -f1 -d":"); do id $user; done Cheers, Mr_Macc 2016-05-14T07:04:44+08:002016-05-14T07:04:44+08:00 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 MitchellK 2016-07-25T00:24:46+08:002016-07-25T00:24:46+08:00 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.
List all users with a
/home
folder:or all users with a
UID >= 1000
:a combination
or for all entries
More information here
You can find it easily by just using
cut
:-d:
sets the delimiter as:
forcut
-f1,3
extracts the field 1 and 3 only delimited by:
from the/etc/passwd
fileCheck
man cut
to get more idea.Example :
If you have
ldap
configured, to include theldap
users in the output :Alternatively to list all users including UID and GID information.
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.