lsof
List open files and the processes that opened them
Overview
Lists information about files opened by processes. Since everything in Linux is a file (including network sockets), lsof is useful for debugging and system administration.
Syntax
lsof [options]Common Options
-i [address]Select by Internet address (shows network connections).
-p PIDSelect by PID.
-u USERSelect by user name or UID.
-c COMMANDSelect by command name.
+D DIRECTORYRecursively search all files in a directory.
-tTerse output (PIDs only).
-nDo not convert network numbers to host names.
-PDo not convert port numbers to port names.
Examples
List all open files.
Show processes using port 80.
Show processes using SSH port.
Show all TCP connections.
Show all network connections with numeric addresses/ports.
Show all files opened by nginx user.
Show all files opened by process 1234.
Show all files opened by nginx processes.
Show all open files in /var/log directory.
Show what processes have syslog open.
Kill all processes using port 3000.