Sorting Human Users from System Users

Every Linux system has a bunch of system accounts (root, uucp, daemon, etc.) in addition to regular users. They’re all lumped together in /etc/password. How do you list your human users separately from system accounts?

Take advantage of Linux’s user identification (UID) numbering scheme and awk’s ability to sort by fields or columns. This is for a Debian or Slackware system:

$ awk -F: ‘$3 > 999 { print $0}’ /etc/passwd
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
carla:x:1000:1000::/home/carla:/bin/bash
foober:x:1001:1001::/home/test:/bin/false
bitchkat:x:1002:1002::/home/test2:/bin/bash
colby:x:1003:1003::/home/test3:/bin/bash

To show a subset use:

$ awk -F: ‘($3 >= 1000) &&($3 <=1005) { print $0}’ /etc/passwd

This is for a Red Hat or SuSE system:

$ awk -F: ‘$3 > 499 { print $0}’ /etc/passwd

To sort them alphabetically use:

$ awk -F: ‘$3 > 499 { print $0}’ /etc/passwd | sort