lsof
List open files and the corresponding processes. tldr-pages
On several platforms 4 Sigma rules name it
Several platforms
List open files and the corresponding processes. Note: Root privileges are required to list files opened by others.
Find the processes that have a given file open
lsof path/to/fileIdentifyTrips 2 Sigma rules: lowSystem Network Connections Discovery - Linux by Daniil Yugoslavskiy, oscd.community; informationalSystem Network Connections Discovery - MacOs by Daniil Yugoslavskiy, oscd.community
Find the process that opened a local internet port
lsof -i :portIdentifyTrips 2 Sigma rules: lowSystem Network Connections Discovery - Linux by Daniil Yugoslavskiy, oscd.community; informationalSystem Network Connections Discovery - MacOs by Daniil Yugoslavskiy, oscd.community
Only output the process ID (PID)
lsof -t path/to/fileIdentifyTrips 2 Sigma rules: lowSystem Network Connections Discovery - Linux by Daniil Yugoslavskiy, oscd.community; informationalSystem Network Connections Discovery - MacOs by Daniil Yugoslavskiy, oscd.community
List files opened by the given user
lsof -u usernameIdentifyTrips 4 Sigma rules: lowLocal System Accounts Discovery - MacOs by Alejandro Ortuno, oscd.community; lowLocal System Accounts Discovery Attempt - Linux by Alejandro Ortuno, oscd.community, CheraghiMilad; lowSystem Network Connections Discovery - Linux by Daniil Yugoslavskiy, oscd.community; informationalSystem Network Connections Discovery - MacOs by Daniil Yugoslavskiy, oscd.community
List files opened by the given command or process
lsof -c process_or_command_nameIdentifyTrips 2 Sigma rules: lowSystem Network Connections Discovery - Linux by Daniil Yugoslavskiy, oscd.community; informationalSystem Network Connections Discovery - MacOs by Daniil Yugoslavskiy, oscd.community
List files opened by a specific process, given its PID
lsof -p process_idIdentifyTrips 2 Sigma rules: lowSystem Network Connections Discovery - Linux by Daniil Yugoslavskiy, oscd.community; informationalSystem Network Connections Discovery - MacOs by Daniil Yugoslavskiy, oscd.community
List open files in a directory
lsof +D path/to/directoryIdentifyTrips 2 Sigma rules: lowSystem Network Connections Discovery - Linux by Daniil Yugoslavskiy, oscd.community; informationalSystem Network Connections Discovery - MacOs by Daniil Yugoslavskiy, oscd.community
Find the process that is listening on a local IPv6 TCP port and don't convert network or port numbers
lsof -i6TCP:port -sTCP:LISTEN -n -PIdentifyTrips 2 Sigma rules: lowSystem Network Connections Discovery - Linux by Daniil Yugoslavskiy, oscd.community; informationalSystem Network Connections Discovery - MacOs by Daniil Yugoslavskiy, oscd.community