Skip to content

lsof Linux Command Guide

The lsof command in Linux allows users to list all the open files and processes that are currently running. It can be used to identify which files are being accessed by which processes, making it a valuable tool for system administration and troubleshooting. By using lsof, you can manage your system resources more efficiently and gain insights into the activities of running processes.

Terminal window
lsof [options] [parameters]
OptionDescription
-cList files opened by processes
-FOutput custom field delimiter
-iList internet and network files
-tDisplay only PIDs
-uList files opened by user
-pList files opened by process ID
ParameterDescription
PIDProcess ID to show files for
usernameUser name to show files for
filenameList files opened by filename
directoryList files opened in directory
portList files opened on port number
deviceList files opened on device number
Terminal window
lsof

Display a list of all open files in the system.

Terminal window
lsof -u username

Show all open files for a specific user by specifying their username.

Terminal window
lsof /path/to/file

Identify the processes that are currently using a specific file or directory.

Terminal window
lsof -i

List all open network connections with associated IP addresses and ports.

Terminal window
lsof -p PID

Display all files opened by a specific process ID (PID).

Show open files for a specific process name

Section titled “Show open files for a specific process name”
Terminal window
lsof -c process-name

List all files opened by processes with a specific name.

Terminal window
lsof +D /path/to/directory

Display all open files within a specific directory.

To use the lsof command in Linux, execute the following command:

Terminal window
lsof --version

The lsof command in Linux is used to list open files and the processes that opened them.

Terminal window
lsof /path/to/file

How can I list all network connections with lsof?

Section titled “How can I list all network connections with lsof?”

You can list all network connections using lsof by running the following command:

Terminal window
lsof -i

How do I display processes listening on specific ports with lsof?

Section titled “How do I display processes listening on specific ports with lsof?”

To display processes listening on specific ports, use the following command syntax with lsof:

Terminal window
lsof -i :port_number

How can I show all files opened by a specific user with lsof?

Section titled “How can I show all files opened by a specific user with lsof?”

To show all files opened by a specific user, run the following lsof command:

Terminal window
lsof -u username

How can I find which process is using a specific file with lsof?

Section titled “How can I find which process is using a specific file with lsof?”

To find which process is using a specific file, execute the following command using lsof:

Terminal window
lsof /path/to/file
  • Viewing open files and sockets
  • Monitoring network connections
  • Troubleshooting processes that are holding onto files
  • Identifying which process is using a specific file or directory
  • Checking for deleted files that are still open by processes
  • Investigating memory usage by processes
  • Finding potential security vulnerabilities such as open ports or file leaks