lsof: List Open Files and Ports

How to use lsof to check open files, listening ports, and process file handles on Linux.
June 12, 2026

lsof: List Open Files and Ports

lsof is a command that lists all open files on the current system.
In Linux, everything — including network sockets, pipes, and devices — is treated as a file, so lsof can check not only regular files but also open ports and resources in use by processes.

1. Check All Open Files

Running it without any options lists all open files across the entire system.
List all open files
sh

2. Check Listening Ports

Use the -i option to filter network sockets.
Combining -P (show port numbers as numbers) and -n (skip hostname reverse lookup) speeds up the results.
Check all listening ports
sh
To find the process occupying a specific port, specify :port.
Check which process is using port 8080
sh

3. Check Open Files by Process

Use the -p option to list files opened by a specific PID.
Check open files by PID
sh
To search by process name, use the -c option.
Check open files by process name
sh

4. Check Open Files by User

Use the -u option to list all files opened by a specific user.
Check open files by user
sh
To exclude a specific user, prefix with ^.
Exclude root user from results
sh

5. Check Which Process Is Using a File

Check which process is using a specific file.
This is especially useful when a file cannot be deleted or umount fails.
Check which process is using a specific file
sh
The same approach works for finding processes occupying an entire mount point.
Check which process is using a mount point
sh
lsof is an essential command for a wide range of situations including debugging port conflicts, recovering deleted files, and tracking process resource usage.

Option Summary

OptionDescriptionExample
noneList all open files system-widelsof
-iFilter network socketslsof -i
-i :PORTFind process using a specific portlsof -i :8080
-PShow port numbers instead of service nameslsof -i -P
-nSkip hostname reverse lookup (faster)lsof -i -n
-p PIDList files opened by a specific PIDlsof -p 1234
-c NAMEFilter by process namelsof -c nginx
-u USERList files opened by a specific userlsof -u root
-u ^USERExclude a specific userlsof -u ^root
Jooojub
System S/W engineer
Explore Tags
Series
    Recent Post
    © 2026. jooojub. All right reserved.