Sort with field separator
Try the below code, Sort the /etc/passwd
based on uid.
sort -n -t ':' -k3 /etc/passwd
There is a specific command for sorting the /etc/passwd
file by UID:
# pwck -s
Just to be safe, you should use this instead of generic sort
if you're sorting the actual, active /etc/passwd
file for your system, as pwck
will handle the necessary file locking correctly. Otherwise strange things might happen if someone attempted to log in or even query some user information while you're replacing the /etc/passwd file.