Article Directory
lsof
It is a command-line tool used to list open files in the current system. It can display all open files in the system, including network connections, pipes, devices, directories, and ordinary files.
lsof
The basic syntax of the command is as follows:
lsof [options]
Among them, options
is an optional parameter, which can be used to specify lsof
the output format, filter conditions, etc.
The following are some commonly used lsof
command options:
-a
: Indicates logical AND, used to specify the relationship between multiple filter conditions;-c
: Indicates to filter by process name;-d
: Indicates to filter by file descriptor;-g
: Indicates to filter by group ID;-i
: Indicates to filter by network connection;-p
: Indicates to filter by process ID;-u
: Indicates to filter by user ID;-t
: Indicates that only the process ID is output;-F
: Indicates the specified output format;-h
: Indicates that the column name is not displayed;-n
: Indicates that the host name is not resolved;-P
: Indicates that the port number is not parsed;-r
: Indicates the specified output interval time;-s
: Indicates to filter by file size;-T
: indicates the specified output format.
For example, to list all open files, the following command can be used:
lsof
To list the files opened by a specified process, the following command can be used:
lsof -p <pid>
To list the files opened by a specified user, the following command can be used:
lsof -u <username>
To list the processes for a specified filename, the following command can be used:
lsof <filename>
To list the processes for a specified port number, the following command can be used:
lsof -i :<port>
To list open files in a specified directory, you can use the following command:
lsof <directory>
In addition to the commonly used options above, lsof
it also supports many other options, and you can man lsof
view the complete help documentation through the command.