>_ IzzyLab

Hands-on task

This task is step 5 of the course “cut, sort, uniq and friends”

User with the highest UID

medium~5 min

Among users with a home directory in /home, find the one with the highest UID and write their name to /root/maxuid.txt. Take the data from /etc/passwd (fields separated by :, UID is the third), and compare UIDs as numbers.

What you'll practise:
  • sort
  • -t delimiter
  • -k field
  • -n numeric sort
  • cut/tail

Topic breakdown

By default sort compares lines lexicographically, so 10000 comes before 3000 (character by character 1<3). The -n flag enables numeric comparison; -t sets the field delimiter, -k N the field to sort by. The combination sort -t: -k3,3n orders /etc/passwd by numeric UID; tail -1 gives the maximum, head -1 the minimum. A standard technique for parsing columnar data without external tools.

What's checked

  1. correct user (max UID)
  2. matches the numeric sort

What it looks like