LinuxCommandLibrary

lsof

lists open files

TLDR

List all open files

$ lsof
copy
Files opened by user
$ lsof -u [username]
copy
Files opened by process
$ lsof -p [pid]
copy
Files using port
$ lsof -i :[port]
copy
Network connections
$ lsof -i
copy
Files in directory
$ lsof +D [/path/to/dir]
copy
Process using file
$ lsof [/path/to/file]
copy

SYNOPSIS

lsof [options] [files]

DESCRIPTION

lsof (List Open Files) is a diagnostic tool that reports all files currently opened by running processes. In Unix-like systems, the concept of a "file" extends well beyond regular files on disk -- it includes network sockets, Unix domain sockets, pipes, device files, and directories. Each open file is represented internally by a file descriptor, and lsof maps these descriptors back to the processes that hold them.
This makes lsof an essential troubleshooting tool for a wide range of scenarios. It can identify which process is listening on a specific TCP/UDP port (`-i :port`), find processes preventing a filesystem from being unmounted (`+D /mount`), or reveal network connections established by a particular program. The output includes the process name, PID, user, file descriptor number, file type, and the file path or network address, providing a comprehensive view of how processes interact with system resources.

PARAMETERS

FILES

Specific files to check.
-u USER
Files opened by user.
-p PID
Files opened by process.
-i [ADDR]
Network connections.
+D DIR
Files in directory.
-c COMMAND
Files opened by command.
--help
Display help information.

CAVEATS

Requires root for all files. Output can be verbose. Performance impact on large systems.

HISTORY

lsof was created by Vic Abell in 1988 and has become a standard Unix diagnostic tool.

SEE ALSO

fuser(1), netstat(8), ss(8), ps(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community