Lsof command example

Source: Internet
Author: User
Tags unix domain socket

What is the lsof command?

Lists information about files opened by processes. The opened file can be

1. Common files

2. Directory

3. Network File System Files

4. Character Device File

5. (function) Shared Library

6. Pipe, Named Pipe

7. Symbolic Links

8. Underlying socket text stream, network socket, and Unix domain socket

How to Use lsof

Here we will introduce the use of lsof commands in the form of cases.

1. List all open files:

Lsof

NOTE: If no parameters are added, all opened files will be opened. We recommend that you add the parameters to locate them.

2. check who is using a file

Lsof/filepath/File

3. recursively view the file information of a directory

Lsof + D/filepath/filepath2/

NOTE: If + D is used, all subdirectories and files in the corresponding directory will be listed.

4. Use the + D option to traverse all the file information in a directory.

Lsof | grep '/filepath/filepath2 /'

5. list information about files opened by a user

Lsof-u Username

Note:-u option. U is short for user.

6. ListProgramOpened file information

Lsof-C MySQL

Note: The-C option will list all program files starting with MySQL. In fact, you can also write lsof | grep MySQL, however, the first method obviously requires a few characters less than the second method.

7. list multiple open files in multiple programs

Lsof-C mysql-C Apache

8. list information about a user and files opened by a program.

Lsof-U test-C MySQL

9. list information about files opened in addition to an outdoor Device

Lsof-u ^ Root

Note: ^ before the user name, the process opened by the root user will not be displayed.

10. display the file opened by a process number

Lsof-P 1234

11. List the file information corresponding to multiple process numbers

Lsof-P 123,456,789

12. List the files opened by other process numbers except for a specific process number.

Lsof-P ^ 1343

13. list all network connections

Lsof-I

14. list all TCP network connection information

Lsof-I TCP

15. list all UDP network connection information

Lsof-I UDP

16. List who is using a port

Lsof-I: 3306

17. List who is using a specific UDP port

Lsof-I UDP: 55

Specific TCP port

Lsof-I TCP: 80

18. list all active network ports of a user

Lsof-a-u test-I

19. list all network file systems

Lsof-n

20. Domain Name socket File

Lsof-u

21. File Information opened by a user group

Lsof-G 5555

22. List the corresponding file information based on the file description

Lsof-D description (like 2)

23. list file information according to the description range of the file

Lsof-D 2-3

Original

Http://hi.baidu.com/jenningsloy318/item/29525f79d827033a70442355

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.