Thursday, March 29, 2012

lsof command with examples

lsof command with examples

lsof stands for list open files. Which will list information about files opened by processes.


Command to show all opened Internet sockets
#lsof -i

Command to print all tcp connections
#lsof -i tcp

Command to print all udp connections
#lsof -i udp

Command to find who are the users using the folder right now
#lsof +D /tmp

Command to print who and what are the files using in /dev/sda5 partitions
#lsof /dev/sda5

Command to list all the files associated with process ID 2665
#lsof +p 2665

Command to listing of files for processes executing the command that begins with vmstat
#lsof -c vmstat

Listing of files for processes executing the command that begins with character a
#lsof -c a

Command to print all the files opened by the user rajkumar
#lsof -u rajkumar

Scenario:
========

Suppose consider that you are usnig nfs to transfer files between multiple systems in you local LAN. Assume that the folder which shares for NFS is /sharing, if you what to find out who all are the user’s using the folder means use the below command

#lsof +D /sharing

The above command will display who all the user’s using the folder right now.