We earn commission when you buy through affiliate links.

This does not influence our reviews or recommendations.Learn more.

Its main function is to retrieve details about various types of files opened up by different running processes.

Well first cover itsinstallationand then some commonusage examplesin this article.

Installing lsof

lsofisnt available by default on mostLinux distributionsbut can be easily installed.

Well now review the supported values for both these fields.

To get a complete list of supportedTYPEin lsof, refer itsmanpage.

Common Usage

Below are some of the popular usage of the lsof command.

This can be useful in automation and scripting as shown in the previous example by combining it withkillcommand.

If you dont want to recursively list files inside sub-directories, use-dflag followed by directory path.

Repeat mode

lsof can be run in repeat mode.

In repeat mode, lsof will generate and print output at regular intervals.

Again, there are two repeat modes supported by lsof, i.e., with-rand+rflags.

Additionally, we can specify time delay with-ror+rflag.

As such we can list details of open web link connections using-iflag.

As such, those files dont list on normal file system listing usinglscommand etc.

Its a useful utility in day-to-day system and internet administration tasks.

Refer lsof man page to learn all supported arguments and their usage.