How to do a netstat that will only filter based on pid

12,689

netstat itself does not support such filtering.

You probably have to do something like:

sudo netstat -lp --inet | grep " $pid/"
Share:
12,689

Related videos on Youtube

Hyun SU  Lee
Author by

Hyun SU Lee

Updated on September 18, 2022

Comments

  • Hyun SU  Lee
    Hyun SU Lee over 1 year

    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  
    
  • Hyun SU  Lee
    Hyun SU Lee over 9 years
    thanks worked great. sudo netstat -lp --inet | grep "$7609/"