Hackbydoing Academy tool guide · Linux command line essentials · free, no login
sort puts lines in order — alphabetically by default, or by number or size when you add the right switch.
sort -t- -k2 -n /logs/scan-001.txt | tail -5
It splits each line at the dashes, orders the lines by the number in the second chunk, and shows you the five biggest at the end.
| - | A lone dash where a file name would go is not a flag: it means 'read from the pipe (standard input) instead of from a file', so sort can order whatever the previous command sends it. |
| -h | Human-readable sort: understand sizes written the way df and du print them (like 4K, 20M, 31G) and order them by real size, smallest first. |
| -hr | Two switches stuck together: -h (understand K/M/G sizes) plus -r (reverse), giving biggest size first — the classic way to find what is eating the disk. |
| -k2 | -k means 'sort by this column (key)', and the number stuck to it is its value: here 2, so lines are ordered by their second field (chunk of text) instead of the whole line. |
| -n | Numeric sort: treat the text as numbers, so 9 comes before 10 — without it, sort reads text letter by letter and puts '10' before '9'. |
| -nr | Two switches stuck together: -n (sort as numbers) plus -r (reverse the order), giving biggest number first. |
| -rn | The same pair as -nr — -r (reverse) plus -n (numeric) — biggest number first. The order of letters in a bundle does not matter. |
| -t- | -t names the character that splits a line into fields, and the character stuck to it is its value: here a dash, so fields are the pieces between '-' characters. Pair it with -k to sort by one of those pieces. |
Only run sort on systems you own or have explicit, written permission to test — at work that means a signed engagement, at home that means your own lab. Inside Hackbydoing Academy you practice on simulated networks and lab machines built for exactly this, where breaking things is the lesson and no one else's systems are involved. Learning how a tool works also teaches you what it looks like from the defender's chair: the logs it leaves, the traffic it makes, and the settings that shut it down.
Reading about sort is step one. In the Academy you run it yourself, step by step, in guided labs on simulated networks — 185 rooms covering attack and defense, from your first scan to full operations, with a defender's debrief at the end of every room. Founding membership is $9.99/mo for the first 500 members.
Join Hackbydoing Academy →Free from the Hackbydoing Academy — learn cybersecurity by doing: real tools, guided labs, attack and defense, on simulated networks. More free material: Tool Guides index · Free Downloads Library · Hackbydoing Academy · Print this page (Ctrl/Cmd+P) for a clean paper copy.