3

I use that :

sudo watch lsof -i -4 -a -P

and it returns a list.

how to get the count?

I tried this but doesn't work.

sudo watch lsof -i -4 -a -P | wc -l
seatoskyhk
  • 151
  • 1
  • 3

3 Answers3

3

I agree, this should probably be on ServerFault.

But, until then:

The issue with what you are doing is the watch command. Watch repeats a command so that you can see the output again and again over time.

My lsof doesn't accept a -4 argument, but if yours does, then

sudo lsof -i -4 -a -P | wc -l

Works for me.

Cargo23
  • 131
  • 3
2

To get the count, you need escape quotes to contain the entire command for the shells spawned by watch:

(Also, -4 didn't work here)

sudo watch "lsof -i -a -P | wc -l "
bahamat
  • 6,263
  • 24
  • 28
Paul
  • 1,634
  • 15
  • 19
1

try netstat -a | wc -l for all type of open sockets and netstat -l | wc -l for displaying server sockets.

Lucas Kauffman
  • 16,880
  • 9
  • 58
  • 93
pritam
  • 111
  • 2