26

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

heemayl
  • 90,425
  • 20
  • 200
  • 267
a06e
  • 12,613
  • 25
  • 66
  • 102

5 Answers5

34

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.
  • 89,123
  • 21
  • 245
  • 323
15

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
  • 90,425
  • 20
  • 200
  • 267
  • 1
    You should use `getent passwd` instead of /etc/passwd since the latter won't include ldap users – Daenyth Jul 06 '15 at 23:16
  • @Daenyth [My initial answer](http://askubuntu.com/revisions/645246/1) was that actually..then for the sake of simplification (and considering no `ldap`) i have moved to teh current one..anyway edited :) – heemayl Jul 06 '15 at 23:25
1

Alternatively to list all users including UID and GID information.

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

Cheers,

J Kluseczka
  • 107
  • 5
Boschko
  • 141
  • 5
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
  • 4