How to List Open Files and Processes in Ubuntu
This article explains how to identify open files and their associated processes on Ubuntu using the command line. It focuses on the primary utility designed for this task, providing essential syntax and common examples to help system administrators and users monitor system activity effectively.
The lsof Command
The command used to list open files and the processes that opened
them is lsof, which stands for โList Open Files.โ In
Unix-like systems such as Ubuntu, everything is treated as a file,
including network connections and hardware devices. Therefore,
lsof provides a comprehensive view of system resources
currently in use.
Basic Usage
To view all open files on your system, open the terminal and run the following command:
lsofBecause this generates a large amount of output, it is often helpful to filter the results.
Common Examples
List files opened by a specific user:
lsof -u usernameList files opened by a specific process ID (PID):
lsof -p 1234List network connections using a specific port:
lsof -i :80List all network connections:
lsof -iUsing Sudo
Many system files and processes are owned by root and are not visible
to standard users. To see a complete list of all open files on the
system, prepend sudo to the command:
sudo lsofThis ensures you have the necessary permissions to inspect all active processes and file handles.