Tmux Essentials and Best Practices: A Modern Terminal Multiplexer Guide
Master Tmux essentials and enterprise best practices: session persistence, pane management, custom keybindings, and hardened DevSecOps remote workflows.
Nov 6, 2026Productivity
In the world of Linux system administration and cybersecurity, lsof (List Open Files) is an indispensable tool for investigating what processes are interacting with the system's files, devices, and network sockets. Despite its name, lsof goes beyond just files—it can reveal active network connections, identify which process is using a specific port, or even help detect malicious activity. Understanding how to use it effectively is a key skill for both troubleshooting and security analysis.
In Unix-like systems, everything is treated as a file—from regular text files to directories, devices, sockets, and pipes. The lsof command lists all open files and the processes that opened them. This is valuable because it gives administrators a real-time map of system activity, helping them pinpoint resource usage, locate configuration issues, and monitor suspicious behaviors.
On most modern Linux distributions, lsof comes pre-installed. If it's missing, you can install it using your package manager:
# On Debian/Ubuntu
sudo apt install lsof
# On CentOS/RHEL
sudo yum install lsofRunning lsof without arguments lists all open files:
lsofSince the output can be massive, it's common to combine it with filtering options.
lsof /var/log/syslogShows which process has /var/log/syslog open—useful for log monitoring.
lsof -i :443Reveals which process is using port 443 (HTTPS).
lsof -iLists all processes with network connections.
lsof -iTCP
lsof -iUDPShows only TCP or UDP connections.
lsof -u johnDisplays all files opened by the user john.
lsof -p 1234Lists files opened by process with PID 1234.
lsof -u ^rootShows all open files not owned by root.
When a service fails to start because a port is in use:
sudo lsof -i :8080This reveals the PID of the process using port 8080, allowing you to stop it or reconfigure the service.
If you suspect malware or unauthorized access:
sudo lsof -iReview active connections, looking for unexpected IP addresses or services.
Sometimes a large file is deleted but still occupies disk space because a process holds it open:
sudo lsof | grep deletedThis helps you identify the process so you can stop it and reclaim space.
Security teams use lsof to quickly see which files a compromised process accessed:
sudo lsof -p <pid>The default lsof output columns include:
| Column | Meaning |
|---|---|
| COMMAND | The name of the process. |
| PID | Process ID. |
| USER | Process owner. |
| FD | File descriptor (e.g., cwd, txt, mem, 0u). |
| TYPE | Type of node (e.g., REG, DIR, CHR, FIFO). |
| DEVICE | Device numbers. |
| SIZE/OFF | Size or offset of the file. |
| NODE | Inode number. |
| NAME | Name of the file or resource. |
grep, awk, and netstat for deeper analysis.Because lsof exposes detailed system activity, it requires proper permissions and should only be used by trusted administrators. In the wrong hands, it can help attackers map the system's active services and processes.
The lsof command is a powerful, versatile tool for system administrators, developers, and cybersecurity professionals. From diagnosing stubborn “file in use” errors to detecting unauthorized activity, it gives you an unmatched view of the system's internals. Learning how to filter and interpret its output will not only make you a better troubleshooter but also a more vigilant security practitioner.
Love it? Share this article: