14 January 2020

lsof tips & tricks

pid from port
lsof -i @192.14.166.72:20000

open jar files:
lsof -p | grep jar

Get the list of files opened
lsof –p

Get the count
lsof –p | wc –l

pid listening tcp at specific port:
lsof -i tcp:8888

From gist

#list all ports for tcp
sudo lsof -itcp

#find all things listening on ports
lsof -Pnl +M -i4 | grep LISTEN

#all ports for tcp, dont resolve port name from numbers
sudo lsof -itcp -P

#open files and ports of process #$PID
sudo lsof -p $PID

#only ports of tcp for process #$PID, dont resolve port name, dont resolve ip name
sudo lsof -a -p $PID -P -n -itcp

#only ports of tcp for process #$PID, dont resolve port name, dont resolve ip name, refresh every 5 seconds
sudo lsof -a -p $PID -P -n -itcp -r 5

#search by file (can be slow)
sudo lsof /complete/path/to/file

No comments :

My Blog List

Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.