Sunday, September 11, 2011

Linux/unix command "lsof"

When looking at the operating system one of your best friends will be lsof. lsof stands forlists information about files opened by processes for the following UNIX dialects . As everything under Linux is a file this tool will show you everything you could possible want to know.
Examples how to use “lsof” :
To list all open files:
To list all open IPv4 network files in use by the process
whose PID is 1234 :
lsof -i 4 -a -p 1234
Presuming the UNIX dialect supports IPv6, to list only open
IPv6 network files :
lsof -i 6
To list all files using any protocol on ports 21 of hostnames:

lsof -i @hostname:portnumbers

To list all files using any protocol on any port of
hostname :

lsof -i @hostname