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
- 92,125
You can find it easily by just using cut :
cut -d: -f1,3 /etc/passwd
-d:sets the delimiter as:forcut-f1,3extracts the field 1 and 3 only delimited by:from the/etc/passwdfile
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
- 93,925
Alternatively to list all users including UID and GID information.
for user in $(cat /etc/passwd | cut -f1 -d":"); do id $user; done
Cheers,
- 107
- 5
- 171
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
- 1
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.
- 101