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 filessh
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.
Combining -P (show port numbers as numbers) and -n (skip hostname reverse lookup) speeds up the results.
Check all listening portssh
To find the process occupying a specific port, specify
:port.Check which process is using port 8080sh
3. Check Open Files by Process
Use the -p option to list files opened by a specific PID.
Check open files by PIDsh
To search by process name, use the -c option.
Check open files by process namesh
4. Check Open Files by User
Use the -u option to list all files opened by a specific user.
Check open files by usersh
To exclude a specific user, prefix with ^.
Exclude root user from resultssh
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.
This is especially useful when a file cannot be deleted or umount fails.
Check which process is using a specific filesh
The same approach works for finding processes occupying an entire mount point.
Check which process is using a mount pointsh
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
| Option | Description | Example |
|---|---|---|
| none | List all open files system-wide | lsof |
-i | Filter network sockets | lsof -i |
-i :PORT | Find process using a specific port | lsof -i :8080 |
-P | Show port numbers instead of service names | lsof -i -P |
-n | Skip hostname reverse lookup (faster) | lsof -i -n |
-p PID | List files opened by a specific PID | lsof -p 1234 |
-c NAME | Filter by process name | lsof -c nginx |
-u USER | List files opened by a specific user | lsof -u root |
-u ^USER | Exclude a specific user | lsof -u ^root |