How to use uniq

Hackbydoing Academy tool guide · Linux command line essentials · free, no login

What uniq is, in plain words

uniq works on sorted lines: it squashes runs of identical neighbouring lines into one, which turns a list into a set of unique entries.

A working uniq command

sort /var/log/auth.log | uniq -c

It sorts the log first (uniq only notices duplicates sitting next to each other), then prints each different line once with a count in front of it.

Every piece of the command, explained

-cCount: write how many times each line appeared in front of that line, turning uniq into a counting machine — the standard way to find the most common IP, user or error in a log.

Use it the legal way

Only run uniq 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.

✦ Practice uniq hands-on in a guided lab

Reading about uniq 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 →

Related tool guides

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.