LiSt Open Files (LSOF) is an excellent utility for managing and tracking network connections on your Linux system.
This utility allows you to see what program is operating on an open port, which daemons have established connections, and what ports are open on your server.
You can list open ports, identify connections currently being made to your system, and determine what resources a process is using.
Also, on many Linux systems, LSOF will be installed by default.
Let’s see some example and how this means.
$lsof -i tcp
$lsof -i :80
$lsof -i TCP:80
$lsof -i udp
$lsof -i :www
$lsof -i :6667
The lsof -i command lists all open files associated with Internet connections.
By default, LSOF lists detailed information about each connection.
$lsof -i -U
List all open Internet files.
$watch lsof -i
This allows you to watch on your system with an output change over time.
This list all NFS files in use.
This unmounting a partition, in this case, sda1.
#kill `lsof -t /dev/sda1`
This kills each process, or users to free the partition.
#lsof -i -u^root
List all connection on your server opened. The output will not be the same for the root user.
$lsof -u your_user
List all files on your server used by your_user.
$lsof -c firefox
Find all open files by the program’s name. For example firefox.
$lsof -p ^2628
You can use ^ translate by except to find all files open by all processes except PID 2628.
$lsof -p ^2628 | wc -l
Count the files opens by all processes except PID 2628.
#lsof -a -c httpd -u root
List all opened files by httpd run by root
$lsof -a -c firefox +D /home/your_user/
List all opened files by firefox inside /home/your_user/ folder.
Shows you all open files that have a link count less than 1
lsof | grep deleted
Also, shows you all open files are opened by a program which doesn’t exist in the file system.
You can manually kill/terminate these processes to free up the memory.
The last example is about your program and ports.
tcp 0 0 127.0.0.1:57130 0.0.0.0:* LISTEN
$lsof -i tcp:57130
The output will be GoogleTalkPlugin.I think it does not work properly with Linux, is just my opinion.