Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Lsof detailed explanation

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Only ordinary root users can execute lsof commands. Ordinary users can see the / usr/sbin/lsof command, but ordinary users' execution will display "permission denied".

Let me summarize the usage of the lsof instruction:

Lsof `which httpd` # that process is using the executable file of apache

Lsof abc.txt shows the process of opening the file abc.txt

Lsof-I: 22 know what program port 22 is running now

Lsof-c abc displays the files now opened by the abc process

Lsof-g gid shows the process that belongs to the gid

Lsof + d / usr/local/ displays the files opened by the process in the directory

Lsof + D / usr/local/ is the same as above, but will search the directory under the directory for a long time.

Lsof-d 4 shows processes using fd 4

Lsof-I is used to display eligible processes.

Syntax: lsof-I [46] [protocol] [@ hostname | hostaddr] [: service | port]

46-> IPv4 or IPv6

Protocol-> TCP or UDP

Hostname-> Internet hostname

Hostaddr-> IPv4 location

Service name in service-> / etc/service (can be more than one)

Port-> port number (can be more than one)

Example: TCP:25-TCP and port 25

@ 1.2.3.4-Internet IPv4 host address 1.2.3.4

Tcp@o.ks.edu.tw:ftp-TCP protocol host.ks.edu.tw service name:ftp

Lsof-n does not convert IP to hostname. By default, the-n parameter is not added.

Example: lsof-I tcp@o.ks.edu.tw:ftp-n

Lsof-p 12 to see which files are opened by the process with process number 12

Lsof + |-r [t] controls the repeated execution of lsof. Default is 15s refresh.

-rrecoery lsof will be executed forever until the interrupt signal is received

+ rforce lsof will be executed until no files are displayed

Example: constantly check the current ftp connection: lsof-I tcp@o.ks.edu.tw:ftp-r

Lsof-s lists the size of the open file, leaving it blank if there is no size

Lsof-u username lists open files in UID

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report