Skip to content

/flags/ss/ss-h-no-header

ss -H (--no-header): drop the header line when counting or parsing sockets

The commands on this page have not been executed by our verification runner yet.updated
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

bash
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 | head

The 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.

OptionEffect on output
-H, --no-headerNo header line
-n, --numericNumeric ports and addresses; avoids slow DNS and service lookups
-O, --onelineEach socket on one line, even with -e, -i or -m details
-Q, --no-queuesDrop the Recv-Q and Send-Q columns
-s, --summaryTotals per protocol and state instead of a socket list
-o, -i, -e, -mExtra detail fields (timers, TCP info, extended, memory)

Pitfalls

  • Detail options wrap lines. With -i or -m, ss prints the details on a second, indented line per socket, which breaks wc -l counts. Add -O to keep one line per socket, or count without the detail options.
  • Always use -n in scripts. Name resolution can make ss slow and changes column contents (https instead of 443).
  • Old versions. Older iproute2 releases lack -H; there, skip the first line with tail -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.

Sources