lsof command stands for List Of Open File. This command provides a list of files that are opened. Basically, it gives the information to find out the files that are opened by which process. If you encounter the below error while running the lsof command:
lsof: command not found
You may install the below package as per your choice of distribution.
apt-get install lsof
yum install lsof
dnf install lsof
lsof Command Examples
Running the lsof commands gives us a list of all the open files on the system.
By using the -u option and specifying the username, we get a list of open files for a particular user.
When we use the -i option and specify a port number, we get information about any process running on that port.
When we use both the -i and -u options with a particular username, we get information about the files and commands being accessed by that user.
Find the processes that have a given file open:
Find the process that opened a local internet port
lsof -i :port