28

How can I list all users along with their UIDs? I want to do this from the terminal.

heemayl
  • 91,753
a06e
  • 13,223
  • 26
  • 70
  • 104

5 Answers5

35

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

A.B.
  • 90,397
17

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
heemayl
  • 91,753
2

Alternatively to list all users including UID and GID information.

for user in $(cat /etc/passwd | cut -f1 -d":"); do id $user; done 

Cheers,

Boschko
  • 151
0

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

0

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.

MitchellK
  • 101