Home>Article>Operation and Maintenance> What does the lsof command mean in linux?
lsof (list open files) is a tool that lists open files on the current system. In the Linux environment, everything exists in the form of files. Through files, you can access not only regular data, but also network connections and hardware.
(Recommended tutorial:linux tutorial)
So, the function of lsof is very powerful. Generally, only root users can execute the lsof command. Ordinary users can see the /usr/sbin/lsof command, but "permission denied" will be displayed when executed by ordinary users. Therefore, being able to view this list through the lsof tool will be very helpful for system monitoring and troubleshooting.
Enter lsof in the terminal to display the files opened by the system. Because lsof needs to access core memory and various files, it must be run as the root user to fully exert its functions.
#Each line displays one open file. If no conditions are specified, all files opened by all processes will be displayed by default. The meaning of each column of information output by lsof is as follows:
COMMAND: name of the process
PID: process identifier
USER: process owner
FD: A file descriptor by which the application identifies the file. Such as cwd, txt, etc.
TYPE: file type, such as DIR, REG, etc.
DEVICE: the name of the specified disk
SIZE: the size of the file
NODE: Index node (identification of the file on the disk)
NAME: The exact name of the open file
The usage of the lsof command is as follows:
lsof abc.txt 显示开启文件abc.txt的进程 lsof 目录名 查找谁在使用文件目录系统
lsof -i :22 Know which process is occupying port 22
lsof -c abc Display the files currently opened by the abc process
lsof -g gid Display the process status of the belonging gid
lsof -n does not convert IP to hostname, the default is not to add the -n parameter
lsof -p 12 See which files are opened by the process with process number 12
lsof -u username View which files the user has opened
lsof -i @192.168.1.111 View remote open network connections (connected to 192.168.1.111)
The above is the detailed content of What does the lsof command mean in linux?. For more information, please follow other related articles on the PHP Chinese website!