1

How can I have the following command below just show/filter based on the PID's I'm looking for?

sudo netstat -lp --inet

The results come back as this

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 *:1508                  *:*                     LISTEN      7609/kodi.bin   
tcp        0      0 *:38565                 *:*                     LISTEN      18079/Plex Plug-in 
tcp        0      0 *:59240                 *:*                     LISTEN      24656/Plex Plug-in 
tcp        0      0 *:46185                 *:*                     LISTEN      18427/Plex Plug-in 
tcp        0      0 *:netbios-ssn           *:*                     LISTEN      989/smbd        
tcp        0      0 *:34061                 *:*                     LISTEN      25066/Plex Plug-in 
tcp        0      0 *:59310                 *:*                     LISTEN      18190/Plex Plug-in 
tcp        0      0 *:50383                 *:*                     LISTEN      18243/Plex Plug-in 
tcp        0      0 *:48336                 *:*                     LISTEN      18081/Plex Plug-in 
tcp        0      0 *:32400                 *:*                     LISTEN      17990/Plex Media Se
tcp        0      0 *:1136                  *:*                     LISTEN      7609/kodi.bin   
tcp        0      0 localhost:http-alt      *:*                     LISTEN      21149/syncthing 

I just want the lines with the PID 7609/kodi.bin in them. so the final output would look like the example below.

tcp        0      0 *:1508                  *:*                     LISTEN      7609/kodi.bin
tcp        0      0 *:1136                  *:*                     LISTEN      7609/kodi.bin  
1

netstat itself does not support such filtering.

You probably have to do something like:

sudo netstat -lp --inet | grep " $pid/"
  • thanks worked great. sudo netstat -lp --inet | grep "$7609/" – Rick T Jan 18 '15 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.