Privacy Policy
© 2025 linux101.dev

lsof Command Cheatsheet

lsof, which stands for "list open files," is a powerful command-line utility for listing all open files and the processes that are using them. In Linux, "everything is a file," so `lsof` can identify processes using regular files, directories, network sockets, and more.

Common Usage

CommandDescription
lsofLists all open files on the system. This can be a very long list.
lsof [FILE_PATH]Lists processes that have a specific file open. This is useful for troubleshooting "file in use" errors.
lsof -iLists all network connections (sockets).
lsof -i :[PORT]Lists processes using a specific network port. For example, `lsof -i :80`.
lsof -c [PROCESS_NAME]Lists files opened by a specific process name. For example, `lsof -c nginx`.
lsof -u [USER_NAME]Lists files opened by a specific user. For example, `lsof -u root`.

Key `lsof` Flags

FlagDescription
-iLists network files. You can combine it with protocols (-i tcp) or ports (-i :80).
-cSelects processes by command name.
-uSelects processes by user ID or name.
-pSelects processes by Process ID (PID). For example, `lsof -p 12345`.
-nPrevents the conversion of IP addresses to hostnames. Speeds up the command.
-PPrevents the conversion of port numbers to service names. Speeds up the command.