lsof (list open files) is a powerful command-line utility in Unix-like operating systems, including Linux, that displays a list of files currently opened by running processes. In Unix-based systems, almost everything is treated as a file, including regular files, directories, sockets, pipes, and device files, making lsof
a versatile tool for system administration.
Key uses of lsof
include:
- Identifying processes using a file or directory: You can find out which process has a particular file open, which is useful for troubleshooting issues like being unable to unmount a filesystem.
- Monitoring network connections:
lsof
can list open network sockets, showing which processes are listening on which ports, making it useful for diagnosing network-related issues. - Finding processes using a specific port: You can use
lsof
to see which process is using a particular network port, which is helpful in resolving port conflicts. - Tracking resource usage: It helps in monitoring which files or resources are being used by which processes, aiding in system optimization and debugging.
An example command would be lsof /path/to/file
to see which processes have a specific file open, or lsof -i :80
to see what process is using port 80.