Linux command-lsof View process open those files or view files for that process using

Source: Internet
Author: User

What is the lsof command?

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

1. Common files, 2. Directory 3. File of the network file system, 4. Character device file 5. (function) shared Library 6. Pipelines, Named Pipes 7. Symbolic Links

8. Bottom socket stream, network Socket,unix domain name socket

9. In Linux, most of the stuff is used as files ... there's a lot more.

How to use Lsof

Here we mainly use the form of case to introduce lsof command.

1. List all open files:

Lsof

Note: If you do not add any parameters, it will open all open files, it is recommended to add a parameter to the specific positioning

2. See who is using a file

Lsof/filepath/file

3. Recursively view file information for a directory

Lsof +d/filepath/filepath2/

Note: Using +d, all subdirectories and files in the corresponding directory will be listed

4. Traverse the method of viewing all file information for a directory than using the +D option

lsof | grep '/filepath/filepath2/'

5. List file information opened by a user

Lsof-u username

Note:-u option, U is actually the user's abbreviation

6. List the file information opened by a program

Lsof-c MySQL

Note: the-C option will list all files that start with MySQL, but you can also write lsof | grep mysql, but the first method is significantly less than the second one.

7. List more open file information for multiple programs

Lsof-c mysql-c Apache

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

Lsof-u test-c MySQL

9. List open file information except for a user

Lsof-u ^root

Note: ^ This symbol before the user name, will be the root user opens the process does not let the display

10. Display the open file by a process number

Lsof-p 1

11. list file information for multiple process numbers

Lsof-p 123,456,789

12. Lists file information opened by other process numbers in addition to a process number

Lsof-p ^1

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

A specific TCP port

Lsof-i tcp:80

18. List all active network ports for 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 according to the file description

Lsof-d description (like 2)

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

Lsof-d 2-3

Linux command-lsof View process open those files or view files for that process using

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.