LinuxCommandLibrary

lsof

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 lists open files. On Unix, everything is a file including sockets and devices.
The tool shows processes using files, ports, and directories. Essential for troubleshooting.
lsof lists open files.

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)

Copied to clipboard