15

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

  • cat /etc/passwd – Panther Jul 6 '15 at 20:08
17

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

10

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
  • 1
    You should use getent passwd instead of /etc/passwd since the latter won't include ldap users – Daenyth Jul 6 '15 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 :) – heemayl Jul 6 '15 at 23:25
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.

0

Alternatively to list all users including UID and GID information.

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

Cheers,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.