#!/bin/bash # Returns a list of all users on the system with UID >= 1000 and their home directory and shell # Sorted lexicographically by username # Uses getent passwd so as to include remote users (e.g. LDAP) in the list # getent passwd returns a list of all users on the system, local and remote # it may return duplicates, since a user might be listed identically in multiple nsswitch databases (e.g. files and systemd) # as such, we sort the list and remove duplicates with uniq before processing it # I'm also removing the "nobody" user, since it's a special case and not a real user # passwd entries have the following format: # $username:x:$uid:$gid:$displayname:$home:$shell # e.g. root:x:0:0::/root:/bin/bash # Awk is 1-indexed, so $1 is the username, $2 is the x, $3 is the uid, etc. # the fields we care about are: # $1: username # $3: uid # $7: shell getent passwd | sort -t: -k3 -n | uniq | grep -v '^nobody:' | awk -F: ' $3 >= 1000 { print $1 " (" $3 "): " $7 } '