Today’s command lsof ========================== next command nl

LiSt Open Files.
Using Options
Show us what files are opened by processes whose names starts by ____(bash,iTunes,S, . . . )
     lsof -c S
     lsof -c bash
     lsof -c iTunes
list only Process Id’s (PID) so ls -t list all unique process id running on system which is using some file.
Show us what files are using the process whose PID is 318:
     lsof +p 318

Search for all opened instances of directory ~/Project and all the files and directories it contains:
     lsof +D ~/Project

Show all connections
lsof -i

Show only TCP connections
lsof -iTCP

Show only UDP connections
lsof -iUDP

-i :port shows all networking related to a given port
lsof -i :22

lsof -i| grep LISTEN
lsof -i| grep ESTABLISHED
Grepping for “ESTABLISHED” or “LISTEN” listening connections

Use -a option to combine search terms.
lsof -a -u nandan -i
“show me everything running for user nandan and using some kind of connection”

Use it to kill processes
kill -9 `lsof -a -u nandan -c VLC -t`