{"id":813,"date":"2011-03-13T15:25:06","date_gmt":"2011-03-13T07:25:06","guid":{"rendered":"http:\/\/www.jpuyy.com\/blog\/?p=813"},"modified":"2015-01-05T15:57:56","modified_gmt":"2015-01-05T07:57:56","slug":"lsof-usage","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=813","title":{"rendered":"lsof\u547d\u4ee4\u8be6\u89e3"},"content":{"rendered":"<p>lsof &#8211; list open files\u663e\u793a\u7a0b\u5e8f\u6253\u5f00\u7684\u6587\u4ef6\uff08linux\u4e0b\u6240\u6709\u7684\u6587\u4ef6\uff0c\u7a0b\u5e8f\uff0c\u8fdb\u7a0b\u90fd\u662f\u6587\u4ef6\uff09<\/p>\n<p>root\u7528\u6237\u624d\u80fd\u6267\u884clsof\u547d\u4ee4\uff0c\u666e\u901a\u7528\u6237\u4f1a\u88ab\u62d2\u7edd\u663e\u793a\u6216\u65e0\u663e\u793a\u7ed3\u679c\u3002<\/p>\n<p>\u6839\u636e\u5b9e\u4f8b\u5b66\u4e60\u7528\u6cd5\uff1a<\/p>\n<p>\u663e\u793a\u5df2\u7ecf\u6253\u5f00\u7684\u6587\u4ef6<\/p>\n<pre>lsof<\/pre>\n<p>\u663e\u793a\u6240\u6709\u6253\u5f00\u7684internet\u94fe\u63a5\uff08-i\uff09\uff0cunix socket (-U)<\/p>\n<pre>lsof -i -U<\/pre>\n<p>\u663e\u793a\u88ab\u8fdb\u7a0b1197\u6253\u5f00\u7684ipv4\u7f51\u7edc\u6587\u4ef6\uff0c\u53ef\u4ee5\u770b\u5230\u662fpptpd\u7684\u8fdb\u7a0b\uff0c\u6b63\u5728\u76d1\u542c\u72b6\u6001<\/p>\n<pre># lsof -i 4 -a -p 1197<\/pre>\n<pre>COMMAND PID USER FD TYPE DEVICE SIZE\/OFF NODE NAME\r\npptpd 1197 root 6u IPv4 4181 0t0 TCP *:1723 (LISTEN)<\/pre>\n<p>\u663e\u793a\u6253\u5f00ipv6\u7684\u7f51\u7edc\u6587\u4ef6<\/p>\n<pre># lsof -i 6<\/pre>\n<p>\u663e\u793a\u4f7f\u7528tcp\u534f\u8bae\uff0c22\u7aef\u53e3\uff08\u6216ssh,\u5728\/etc\/service\u4e2d\uff09\u7684ipv4\u548cipv6\u6587\u4ef6<\/p>\n<pre># lsof -i tcp:22\r\n\u6216\r\n# lsof -i tcp:ssh<\/pre>\n<pre>COMMAND PID USER FD TYPE DEVICE SIZE\/OFF NODE NAME\r\nsshd 14873 root 3u IPv4 4100995 0t0 TCP ibm.jpuyy.com:ssh-&gt;114.221.19.245:56544 (ESTABLISHED)\r\nsshd 17248 root 3r IPv4 4149257 0t0 TCP ibm.jpuyy.com:ssh-&gt;114.221.19.245:52610 (ESTABLISHED)\r\nsshd 27849 root 3u IPv4 3235729 0t0 TCP *:ssh (LISTEN)\r\nsshd 27849 root 4u IPv6 3235731 0t0 TCP *:ssh (LISTEN)<\/pre>\n<p>\u663e\u793a\u67d0\u4e2a\u547d\u4ee4\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u5982pptpd<\/p>\n<pre># lsof -c pptpd<\/pre>\n<p>\u663e\u793a\u548cip:1.2.3.4\u6709\u5173\u7684\u6253\u5f00\u7684\u6587\u4ef6<\/p>\n<pre># lsof -i @1.2.3.4<\/pre>\n<p>\u663e\u793a\u548cip:1.2.3.4\u6709\u5173\u7684tcp\u534f\u8baeftp<\/p>\n<pre># lsof -i tcp@1.2.3.4:ftp<\/pre>\n<p>\u663e\u793a\u548cjpuyy\u6709\u5173\u7684\u6253\u5f00\u7684\u6587\u4ef6<\/p>\n<pre>#\u00a0lsof -u jpuyy<\/pre>\n<p>\u4e0d\u65ad\u663e\u793a\u8fde\u5230jpuyy.com\u768480\u7aef\u53e3\u7684\u6253\u5f00\u7684\u6587\u4ef6\uff0c(default fifteen)<\/p>\n<pre># lsof -i @jpuyy.com:80 -r<\/pre>\n<p>\u663e\u793a\/dev\/sdb1\u6253\u5f00\u7684\u6587\u4ef6<\/p>\n<pre>#\u00a0lsof \/dev\/sdb1<\/pre>\n<p>&nbsp;<\/p>\n<p>lsof |sort -k7 -n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>lsof &#8211; list open files\u663e\u793a\u7a0b\u5e8f\u6253\u5f00\u7684\u6587\u4ef6\uff08linux\u4e0b\u6240\u6709\u7684\u6587\u4ef6\uff0c\u7a0b\u5e8f\uff0c\u8fdb\u7a0b\u90fd\u662f\u6587\u4ef6\uff09 root\u7528\u6237\u624d\u80fd\u6267\u884clsof\u547d\u4ee4\uff0c\u666e\u901a\u7528\u6237\u4f1a\u88ab\u62d2\u7edd\u663e\u793a\u6216\u65e0\u663e\u793a\u7ed3\u679c\u3002 \u6839\u636e\u5b9e\u4f8b\u5b66\u4e60\u7528\u6cd5\uff1a \u663e\u793a\u5df2\u7ecf\u6253\u5f00\u7684\u6587\u4ef6 lsof \u663e\u793a\u6240\u6709\u6253\u5f00\u7684internet\u94fe\u63a5\uff08-i\uff09\uff0cunix socket (-U) lsof -i -U \u663e\u793a\u88ab\u8fdb\u7a0b1197\u6253\u5f00\u7684ipv4\u7f51\u7edc\u6587\u4ef6\uff0c\u53ef\u4ee5\u770b\u5230\u662fpptpd\u7684\u8fdb\u7a0b\uff0c\u6b63\u5728\u76d1\u542c\u72b6\u6001 # lsof -i 4 -a -p 1197 COMMAND PID USER FD TYPE DEVICE SIZE\/OFF NODE NAME pptpd 1197 root 6u IPv4 4181 0t0 TCP *:1723 (LISTEN) \u663e\u793a\u6253\u5f00ipv6\u7684\u7f51\u7edc\u6587\u4ef6 # lsof -i 6 \u663e\u793a\u4f7f\u7528tcp\u534f\u8bae\uff0c22\u7aef\u53e3\uff08\u6216ssh,\u5728\/etc\/service\u4e2d\uff09\u7684ipv4\u548cipv6\u6587\u4ef6 # lsof -i tcp:22 \u6216 # lsof [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-813","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=813"}],"version-history":[{"count":10,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/813\/revisions"}],"predecessor-version":[{"id":7052,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/813\/revisions\/7052"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}