Three commands that show up in almost every shell pipeline.
cut -d ':' -f 1 /etc/passwd # just the usernames (field 1)
cut -d ':' -f 1,7 /etc/passwd # username and login shell
cut -c 1-10 /etc/passwd # first 10 characters of each line
-d sets the delimiter (colon, comma, tab, whatever), -f picks
fields by number. -c selects character ranges directly.
Make a small file to follow along (the numbers.txt and sizes.txt
examples below are illustrative variants):
printf 'banana\napple\napple\ncherry\n' > names.txt
sort names.txt # alphabetical
sort -r names.txt # reverse
sort -n numbers.txt # numeric (10 comes after 2, not before)
sort -h sizes.txt # human-readable sizes (10K before 5M)
sort -u names.txt # sorted AND deduplicated in one step
You met sort -h in the disk-usage topic. The rest earn their
keep almost daily.
Important: uniq only removes adjacent duplicates. It's
designed to run after sort.
sort names.txt | uniq # dedupe
sort names.txt | uniq -c # dedupe AND count occurrences
sort names.txt | uniq -c | sort -rn # top-N pattern, biggest first
That last line is one of the most useful DevOps idioms: count how often each unique value appears, then sort by count descending. Perfect for finding the top IPs in an access log, the most frequent error messages, or the busiest endpoints. You'll type it every week.