Your /etc/passwd file can sometimes become disorderly as users come and go on a system. This simple script displays the file sorted numerically by the uid field.
sort -t : -k 3,4 -g /etc/passwd
The -t option identifies the field separator. In this case we use the colon (:). The -k 3,4 option determines the order in which fields will be compared for the sort. We're sorting by the 3rd field (UID) followed by the 4th field (GID). Lastly, the -g option means we want the sort to occur numerically. This makes the number 56 appear after 9. Using the default (ASCII) sort places 56 before 9 (5 comes before 9).
This variation sorts the group file by the group id (GID) field.

tagged with: 
Leave a comment