The lsof
command stands for “list open files.” It is a powerful utility in Unix-like operating systems that allows users to view a list of all open files and the processes that opened them. This can be particularly useful for troubleshooting issues related to file access, monitoring system performance, or identifying which processes are using specific files.
The basic syntax of the lsof
command is as follows:
lsof [options] [arguments]
-a
: AND list the specified options.-c <command>
: Show files opened by the specified command.-u <user>
: Show files opened by the specified user.-p <PID>
: Show files opened by the specified process ID.-i
: Show network files (internet connections).+D <directory>
: List all files opened in the specified directory.Here are some practical examples of using the lsof
command:
lsof
lsof -u username
lsof -p 1234
lsof -i
lsof /path/to/file
lsof +D /path/to/directory
lsof
with grep
to filter results for specific keywords. For example:
lsof | grep keyword
lsof -u username -c command