A very good command of system administration lsof (reprint)

Source: Internet
Author: User
Tags tmp folder

Recently discovered that the LOSF command is particularly useful in system administration, summarizing the information I have collected as follows

1. When there are no parameters behind lsof, the command will list all files that are open by all processes in the current system
#lsof |NL #nl命令打印出行号

2. The following commands indicate the process of opening a file

#lsof ' which httpd ' #那个进程在使用apache的可执行文件
#lsof/etc/passwd #那个进程在占用/etc/passwd
#lsof/dev/hda6 #那个进程在占用hda6
#lsof/dev/cdrom #那个进程在占用光驱

3. The bottom will print the process number of the process that occupies the httpd executable (just the process number, which is useful in writing shell scripts)
#lsof-T ' which httpd '

4. Show those files are opened with the process name of K, start with bash, and begin with Init:
#lsof-C K
#lsof-C Bash
#lsof-C Init

5, show that those files are opened in the process of courier, but does not belong to the user ' Zahn '
#lsof-C Courier-u ^zahn

6. Display files opened by Zahn and Apache
#lsof-U Apache,zahn

7. Show those files are turned on by the PID 30297 process:
#lsof +p 30297

8. Displays all the instance and files opened in the/tmp folder process. But the symbol file is not listed
#lsof-D/tmp

9. Show all open ports
#lsof-I.
10. Display all open 80-port processes
#lsof-I: 80

11. Show all open ports and UNIX domain files:
#lsof-I-u

12. Shows those processes that have opened a link to the UDP 123 (NTP) Port of www.akadia.com:
#[email protected]: 123

13. List Internet, X. (HP-UX), and UNIX domain files:
#lsof-I-u

14. List the IPv4 files opened by the specified process:
#lsof-I 4-a-P 1234 (-a parameter is considered and)

15. List the IPv4 files opened by the specified process:
#lsof-I. 6

16. List files using/dev/log:
#lsof/dev/log

17. Get the PID, command name for each process. Process file descriptor, file device number, file Inode for each file:
#lsof –FPCFDI

18. The 3rd character to get the working directory is the process of ' o ' or ' O ':
#lsof-C/^. O.$/i-a-D CWD (-a parameter is considered and)

19. Obtain and specify the IP-related socket file:
#[email protected]

20. Unlinked Open File:
#lsof +L1

21. Find the socket for monitoring
#lsof –i
#[email protected]
#[email protected]: Ftp-data

22. Find the file used by the specified process number or process name
Lsof-p

23. Remote Login Detection
#lsof/dev/pts/0

24. NFS Files

$ lsof–n

25. Specify user-opened files

Lsof-u ^root

A very good command of system administration lsof (reprint)

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.