1

I can get the socket in listen state opened by an user with this code

lsof -sTCP:LISTEN -n -i -P |awk '$3 == "user" { print $0 }'

I would like to now if there is an option to lsof that also filter by user (or by process name by the way). I know that lsof has the -u option but this:

lsof -sTCP:LISTEN -n -i -P -u username

List all the files opened by user username, it doesn't filter the network connections (and it's slow).

drizzt.dourden
  • 683
  • 8
  • 20

1 Answers1

2

Normally list options that are specifically stated are ORed

Try this instead:

lsof -u username -a -i -sTCP:LISTEN -nP 
Philippe A.
  • 2,885
  • 2
  • 28
  • 37