Low Orbit Flux Logo 2 F

Linux Command - lsof

The Linux lsof command is used to list open files ( or any file handles including sockets ).

NOTE - You need root to view everything.

Show all open file handles:


Which processes have this file open:

lsof /usr/lib/x86_64-linux-gnu/libselinux.so.1

Only print the PID:

lsof -t /usr/lib/x86_64-linux-gnu/libselinux.so.1

All files opened by this command or process:

lsof -c nginx

All files open by this user:

lsof -u user1

All files opened by a specific process ( using PID ):

lsof -p 805

List open files in a dir:

lsof +D /etc

List processes using network ports. Specify UDP or TCP and the port number:

lsof -i TCP:8080  # TCP port 8080
lsof -i TCP:53    # TCP port 53
lsof -i UDP:53    # UDP port 53
lsof -i :53       # TCP and UDP port 53

Specify IPv4 or IPv6:

lsof -i 4TCP:80
lsof -i 6TCP:80

Anything TCP on either interface:

lsof -i TCP@
lsof -i TCP@