A
cd ..
System

Lsof - List Open Files

Inspect open files, network connections, and processes with lsof.

2025-09-19
lsof, debugging, linux

List all open files

lsof

Warning: This produces massive output!

List files opened by specific user

lsof -u username

List files opened by process

lsof -p 1234

List files in directory

lsof +D /var/log

Find process using specific file

lsof /var/log/syslog

List network connections

lsof -i

List connections on specific port

lsof -i :8080

List TCP connections

lsof -i TCP

List UDP connections

lsof -i UDP

Find process listening on port

lsof -i :80 -sTCP:LISTEN

List IPv4 connections

lsof -i 4

List IPv6 connections

lsof -i 6

Show files opened by command

lsof -c nginx

Repeat every N seconds

Monitor every 2 seconds:

lsof -r 2 -i :8080

Exclude user

lsof -u ^root

Combine filters (AND)

Files by user AND process:

lsof -u username -c nginx

Combine filters (OR)

Use -a flag for AND, default is OR:

lsof -i :80 -i :443

Find deleted but open files

lsof | grep deleted

Kill all processes using a file

kill -9 $(lsof -t /path/to/file)

Check who's using mounted filesystem

lsof /mnt/usb

Was this useful?

Share with your team

Browse More