Command to list all users with their UID?
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
You can find it easily by just using cut
:
cut -d: -f1,3 /etc/passwd
-d:
sets the delimiter as:
forcut
-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