Linux · System Tools
lsof
A command-line utility that lists open files and associated processes, providing detailed system resource visibility.
- Lizenz
- BSD-2-Clause
- Aktuelle Version
- 4.99.7
Was ist lsof?
lsof stands for 'list open files' and has been a standard Unix tool for decades. It scans /proc and system calls to report every file handle currently held by any process. While it lacks a graphical interface, its output is comprehensive and scriptable, making it a mature, stable part of nearly every Linux distribution.
It is primarily for system administrators, developers, and power users who need to diagnose why a file cannot be deleted, identify which process is using a specific port, or audit file access. If you are comfortable with the terminal, it is the first tool you reach for when troubleshooting system-level issues or monitoring resource usage in real-time.
Compared to Process Hacker, lsof is far less intuitive for casual users but offers deeper, more granular data via the command line. Process Hacker provides a visual tree of processes and threads, while lsof gives you raw, parseable text. You lose the visual context but gain the ability to pipe results into grep or awk for precise filtering.
Ideal für: Diagnosing file locks, port conflicts, and process resource usage in a terminal environment.
Wichtige Funktionen von lsof
- Lists all open files for specific or all processes
- Identifies processes holding network ports
- Shows file descriptors and their types (regular, socket, pipe)
- Filters by user, process ID, or command name
- Outputs data in a format suitable for scripting
- Reveals hidden files or deleted files still in use
Vorteile
- Extremely lightweight and fast
- Available in all major Linux repositories
- Highly scriptable and flexible
- Provides detailed file descriptor information
Nachteile
- No graphical user interface
- Output can be overwhelming without filtering
- Requires basic terminal knowledge to use effectively
Windows-Programme, die lsof ersetzt
lsof unter Linux installieren
sudo apt install lsofsudo apt install lsofsudo dnf install lsofsudo pacman -S lsofsudo zypper install lsofTipps für Windows-Umsteiger
Unlike Process Hacker, you cannot click to see details; you must use flags. To find what is using port 80, run lsof -i :80. To see all files opened by a specific user, use lsof -u username. There are no file formats to save; the value is in the real-time output. Learn to pipe the output to less or grep to manage the volume of data, as the default output lists every single open file on the system.
lsof: häufige Fragen
How do I find which process is using a specific port?
Use the command lsof -i :port_number. For example, lsof -i :80 shows processes using port 80.
Why can't I delete a file, and how does lsof help?
If a file is in use, it may not delete cleanly. Run lsof | grep filename to find the process holding the file open, then kill that process.
What does the 'FD' column mean in lsof output?
FD stands for File Descriptor. It shows how the process is accessing the file, such as 'r' for read, 'w' for write, or 'u' for read/write.
Is lsof the same as netstat?
No, netstat focuses on network statistics, while lsof lists all open files, including network sockets. lsof is more comprehensive for file-level debugging.
Aktualisiert am