lsof
List Open Files. A powerful tool to identify which files are open by which process. In Linux, everything is a file (network sockets, pipes, etc.), making text extremely versatile for debugging.
Synopsis
lsof [options]
Core Options
-i :portList files (network connections) on a specific port.
-u userList files opened by a specific user.
-p pidList files opened by a specific PID.
+D /pathRecursively search for open files in a directory.
Usage Examples
Check Port Usage
Find out what process is listening on port 8080.
lsof -i :8080List User's Open Files
See everything 'mysql' user has open.
lsof -u mysqlWho is using this file?
Find which process is holding a lock on 'database.db'.
lsof /var/lib/data/database.dbNetwork Connections
List all open network connections.
lsof -iBuilt for builders.