The lsof command is detailed

  

What is the lsof command?

You can list information about files that are opened by the process. The file that is opened can be

1. Normal file, 2. Directory 3. Network file system file, 4. Character device file 5. (Function) Shared library 6. Pipeline, named pipe 7. Symbol Link 8. The underlying socket word stream, network socket, Unix domain name socket 9. In linux, most of the things are treated as files ….. There are many other

How to use lsof

This article mainly introduces the use of the lsof command in the form of a case

1. List all open files:

[root@web1 ~]# lsof

Remarks: If you do not add any parameters, all open files will be opened. It is recommended to add some parameters to locate

2. See who is using a file

[root@ Web1 ~]# lsof /path/file

3. Recursively view file information of a directory

[root@web1 ~]# lsof +D /path/

Remarks: With +D, all subdirectories and files in the corresponding directory will be listed

4. How to traverse all file information in a directory than using the +D option

[root@web1 ~]# lsof |  Grep '/path/'

5. List file information opened by a user

[root@web1 ~]# lsof -u username

Remarks: -u The option, u is actually the abbreviation of user

6. List the file information opened by a program

[root@web1 ~]# lsof -c httpd

Remarks : The -c option will list all files that start with httpd, but you can also write lsof |  Grep httpd, but the first method is obviously a few characters less than the second method

7. List multiple files with multiple open files

[root@web1 ~ ]# lsof -c mysql -c httpd

8. List a user and the file information opened by a program

[root@web1 ~]# lsof -u test -c Mysql

9. List open file information except for a user

[root@web1 ~]# lsof -u ^barlow

Remarks: ^This Before the user name, the symbol will open the process that is open by the barlow user.

10. Display the file opened by a process number

[root@web1 ~]# Lsof -p 1866

11. List file information corresponding to multiple process numbers

[root@web1 ~]# lsof -p 123,456,789

12. List except A process number, file information opened by other process numbers

[root@web1 ~]# lsof -p ^1

Copyright © Windows knowledge All Rights Reserved