linux_commands:lsof
Table of Contents
lsof
The lsof (List Open Files) command is a tool used on Unix and Linux systems to list files opened by processes on the system. It is useful for system administration and troubleshooting, as it helps identify which processes are using files, network sockets, and other resources.
Basic Usage
The general syntax of the command is:
lsof [options]
Common Options
- lsof -i: Displays active network connections and open ports.
- lsof +D <directory>: Lists all files opened within a specific directory.
- lsof -u <user>: Shows files opened by processes of a specific user.
- lsof -c <process_name>: Lists files opened by processes matching the given name.
- lsof -p <PID>: Displays files opened by the process with the given Process ID (PID).
- lsof -t: Only displays the process IDs (PIDs) without additional details.
Examples
- List active network connections:
lsof -i
- Check which process is using a specific port (e.g., port 80):
lsof -i :80
- Find files opened by the process with PID 1234:
lsof -p 1234
- Show files opened by the user “admin”:
lsof -u admin
Utility
lsof is especially useful for:
- Detecting locked or in-use files.
- Diagnosing network issues and occupied ports.
- Identifying which processes are using a specific directory.
linux_commands/lsof.txt · Last modified: 2025/02/18 17:14 by 85.219.17.206
