Linux Command: lsof
List open files and the processes that opened them
lsof (list open files) shows all files opened by processes. In Linux, everything is a file — network sockets, pipes, devices, and regular files — so lsof provides a comprehensive view of system activity. lsof is essential for finding which process is using a port, which processes have a file open (preventing unmount), and diagnosing resource leaks. It is one of the most versatile troubleshooting tools. lsof can filter by user, process, file, network port, and more. It shows the process name, PID, user, file descriptor, type, and file/socket details.
Syntax
lsof [OPTION]...Common Examples
sudo lsof -i :80— Shows which process is listening on port 80.sudo lsof -i -P -n— Shows all network connections without DNS resolution.lsof -p $(pgrep nginx | head -1)— Shows all files opened by the nginx process.lsof /var/log/syslog— Shows processes that have syslog open.
Pro Tips
Master this and 230+ other Linux commands with our comprehensive eBooks and cheat sheets.
Related Resources