ss -H (--no-header): drop the header line when counting or parsing sockets
- tool
- ss / netstat
- command
- ss
- flag
- -H, --no-header
- default
- off (the first line is a column header)
ss -H suppresses the header line that ss normally prints above the socket list. That makes the output safe to pipe into wc -l, awk, sort or monitoring scripts: every line is a socket, so ss -Htn state established | wc -l is exactly the number of established TCP connections. Without -H, the first line (State Recv-Q Send-Q Local Address:Port Peer Address:Port, with variations) is counted as well, and an empty result still prints one line.
Typical uses
ss -Htn state established | wc -l # number of established TCP connections
ss -Htn state established '( dport = :443 )' | wc -l # ... to port 443
ss -Htln | awk '{print $3}' | sort -u # local listening address:port pairs
ss -Htn state time-wait | awk '{print $4}' | cut -d: -f1 | sort | uniq -c | sort -rn | headThe last line counts TIME-WAIT sockets per remote address. Note that the columns shift when a state filter is given: ss then omits the State column, so the peer address moves from field 5 to field 4. Check the column order once with the header before writing the awk program.
Related output options
| Option | Effect on output |
|---|---|
| -H, --no-header | No header line |
| -n, --numeric | Numeric ports and addresses; avoids slow DNS and service lookups |
| -O, --oneline | Each socket on one line, even with -e, -i or -m details |
| -Q, --no-queues | Drop the Recv-Q and Send-Q columns |
| -s, --summary | Totals per protocol and state instead of a socket list |
| -o, -i, -e, -m | Extra detail fields (timers, TCP info, extended, memory) |
Pitfalls
- Detail options wrap lines. With
-ior-m, ss prints the details on a second, indented line per socket, which breakswc -lcounts. Add-Oto keep one line per socket, or count without the detail options. - Always use
-nin scripts. Name resolution can make ss slow and changes column contents (httpsinstead of443). - Old versions. Older iproute2 releases lack
-H; there, skip the first line withtail -n +2. - Counting by state is easier with a dedicated pattern; see count connections by state. Timers per connection come from ss -o.
All filters and columns are summarised in the ss cheat sheet; listening ports are covered in list listening ports.
FAQ
Why is my connection count one too high?
ss prints a header line (State, Recv-Q, Send-Q, Local Address:Port, Peer Address:Port) before the sockets, so wc -l counts it too. Add -H, or subtract one only if you are sure the header is always present.
My ss does not know -H. What now?
Older iproute2 releases lack the option. Use tail -n +2 to skip the first line, or count with ss -s, which prints summary statistics instead of a list.
Does -H also remove the State column?
No. -H removes only the header line. When you filter by state, ss omits the State column by itself, which is why field numbers shift between commands.