feat: update lsof.md cheatsheet. 444f0d850c

This commit is contained in:
jaywcjlove
2022-10-29 19:11:39 +00:00
parent c1da11a02e
commit 900f07b386

View File

@ -40,7 +40,7 @@
<p>这个快速参考备忘单提供了使用 lsof 命令的各种方法。</p>
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
<path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" href="#介绍">介绍</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定于端口">特定于端口</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定于进程">特定于进程</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定于用户">特定于用户</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定于网络">特定于网络</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定的pid">特定的PID</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定文件名">特定文件名</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定目录">特定目录</a><a aria-hidden="true" class="leve3 tocs-link" href="#kill">Kill</a><a aria-hidden="true" class="leve3 tocs-link" href="#参数">参数</a><a aria-hidden="true" class="leve3 tocs-link" href="#示例">示例</a><a aria-hidden="true" class="leve3 tocs-link" href="#文件描述符列表fd">文件描述符列表(FD)</a><a aria-hidden="true" class="leve3 tocs-link" href="#示例列信息">示例列信息</a><a aria-hidden="true" class="leve3 tocs-link" href="#标准输出输入错误文件状态模式fd">标准输出/输入/错误文件状态模式(FD)</a><a aria-hidden="true" class="leve3 tocs-link" href="#文件状态模锁-fd">文件状态模锁 (FD)</a><a aria-hidden="true" class="leve3 tocs-link" href="#文件类型">文件类型</a><a aria-hidden="true" class="leve3 tocs-link" href="#列出指定进程号所打开的文件">列出指定进程号所打开的文件</a><a aria-hidden="true" class="leve3 tocs-link" href="#获取端口对应的进程-idpid">获取端口对应的进程 ID=>pid</a><a aria-hidden="true" class="leve3 tocs-link" href="#列出打开文件的进程">列出打开文件的进程:</a></div></div><div class="h1wrap-body"><div class="wrap"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" href="#介绍">介绍</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定于端口">特定于端口</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定于进程">特定于进程</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定于用户">特定于用户</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定于网络">特定于网络</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定的pid">特定的PID</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定文件名">特定文件名</a><a aria-hidden="true" class="leve3 tocs-link" href="#特定目录">特定目录</a><a aria-hidden="true" class="leve3 tocs-link" href="#kill">Kill</a><a aria-hidden="true" class="leve3 tocs-link" href="#参数">参数</a><a aria-hidden="true" class="leve3 tocs-link" href="#列出指定进程号所打开的文件">列出指定进程号所打开的文件</a><a aria-hidden="true" class="leve3 tocs-link" href="#获取端口对应的进程-idpid">获取端口对应的进程 ID=>pid</a><a aria-hidden="true" class="leve3 tocs-link" href="#列出打开文件的进程">列出打开文件的进程:</a><a aria-hidden="true" class="leve2 tocs-link" href="#示例">示例</a><a aria-hidden="true" class="leve3 tocs-link" href="#示例-1">示例</a><a aria-hidden="true" class="leve3 tocs-link" href="#文件描述符列表fd">文件描述符列表(FD)</a><a aria-hidden="true" class="leve3 tocs-link" href="#示例列信息">示例列信息</a><a aria-hidden="true" class="leve3 tocs-link" href="#标准输出输入错误文件状态模式fd">标准输出/输入/错误文件状态模式(FD)</a><a aria-hidden="true" class="leve3 tocs-link" href="#文件状态模锁-fd">文件状态模锁 (FD)</a><a aria-hidden="true" class="leve3 tocs-link" href="#文件类型">文件类型</a></div></div><div class="h1wrap-body"><div class="wrap"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap"><div class="wrap-header h3wrap"><h3 id="介绍"><a aria-hidden="true" tabindex="-1" href="#介绍"><span class="icon icon-link"></span></a>介绍</h3><div class="wrap-body">
<p><strong>lsof</strong> 表示 <code>L</code>i<code>s</code>t <code>O</code>pen <code>F</code>iles 用于查找哪个进程打开了哪些文件</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">lsof</span>
@ -85,7 +85,8 @@
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">kill</span> <span class="token parameter variable">-9</span> <span class="token variable"><span class="token variable">`</span><span class="token function">lsof</span> <span class="token parameter variable">-t</span> <span class="token parameter variable">-u</span> apache<span class="token variable">`</span></span>
</span><span class="code-line">$ <span class="token function">kill</span> <span class="token parameter variable">-9</span> <span class="token variable"><span class="token variable">$(</span><span class="token function">lsof</span> <span class="token parameter variable">-t</span> <span class="token parameter variable">-i</span> :8080<span class="token variable">)</span></span>
</span></code></pre>
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="参数"><a aria-hidden="true" tabindex="-1" href="#参数"><span class="icon icon-link"></span></a>参数</h3><div class="wrap-body">
</div></div></div><div class="wrap row-span-2"><div class="wrap-header h3wrap"><h3 id="参数"><a aria-hidden="true" tabindex="-1" href="#参数"><span class="icon icon-link"></span></a>参数</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token parameter variable">-a</span> <span class="token comment"># 列出打开文件存在的进程;</span>
</span><span class="code-line">-c<span class="token operator">&#x3C;</span>进程名<span class="token operator">></span> <span class="token comment"># 列出指定进程所打开的文件;</span>
</span><span class="code-line"><span class="token parameter variable">-g</span> <span class="token comment"># 列出GID号进程详情</span>
@ -99,7 +100,17 @@
</span><span class="code-line"><span class="token parameter variable">-h</span> <span class="token comment"># 显示帮助信息;</span>
</span><span class="code-line"><span class="token parameter variable">-v</span> <span class="token comment"># 显示版本信息</span>
</span></code></pre>
</div></div></div><div class="wrap col-span-2"><div class="wrap-header h3wrap"><h3 id="示例"><a aria-hidden="true" tabindex="-1" href="#示例"><span class="icon icon-link"></span></a>示例</h3><div class="wrap-body">
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="列出指定进程号所打开的文件"><a aria-hidden="true" tabindex="-1" href="#列出指定进程号所打开的文件"><span class="icon icon-link"></span></a>列出指定进程号所打开的文件</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token function">lsof</span> <span class="token parameter variable">-p</span> <span class="token variable">$pid</span>
</span></code></pre>
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="获取端口对应的进程-idpid"><a aria-hidden="true" tabindex="-1" href="#获取端口对应的进程-idpid"><span class="icon icon-link"></span></a>获取端口对应的进程 ID=>pid</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token function">lsof</span> <span class="token parameter variable">-i:9981</span> <span class="token parameter variable">-P</span> <span class="token parameter variable">-t</span> <span class="token parameter variable">-sTCP:LISTEN</span>
</span></code></pre>
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="列出打开文件的进程"><a aria-hidden="true" tabindex="-1" href="#列出打开文件的进程"><span class="icon icon-link"></span></a>列出打开文件的进程:</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token function">lsof</span> <span class="token variable">$filename</span>
</span></code></pre>
</div></div></div></div></div><div class="wrap"><div class="wrap-header h2wrap"><h2 id="示例"><a aria-hidden="true" tabindex="-1" href="#示例"><span class="icon icon-link"></span></a>示例</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap col-span-2"><div class="wrap-header h3wrap"><h3 id="示例-1"><a aria-hidden="true" tabindex="-1" href="#示例-1"><span class="icon icon-link"></span></a>示例</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ <span class="token function">lsof</span>
</span><span class="code-line"><span class="token builtin class-name">command</span> PID <span class="token environment constant">USER</span> FD <span class="token builtin class-name">type</span> DEVICE SIZE NODE NAME
@ -116,8 +127,8 @@
</span><span class="code-line">migration <span class="token number">2</span> root rtd DIR <span class="token number">8,2</span> <span class="token number">4096</span> <span class="token number">2</span> /
</span><span class="code-line">migration <span class="token number">2</span> root txt unknown /proc/2/exe
</span></code></pre>
</div></div></div><div class="wrap row-span-4"><div class="wrap-header h3wrap"><h3 id="文件描述符列表fd"><a aria-hidden="true" tabindex="-1" href="#文件描述符列表fd"><span class="icon icon-link"></span></a>文件描述符列表(FD)</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-4-->
</div></div></div><div class="wrap row-span-3"><div class="wrap-header h3wrap"><h3 id="文件描述符列表fd"><a aria-hidden="true" tabindex="-1" href="#文件描述符列表fd"><span class="icon icon-link"></span></a>文件描述符列表(FD)</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-3-->
@ -371,15 +382,6 @@
<table><thead><tr><th align="left">标识</th><th align="left">说明</th></tr></thead><tbody><tr><td align="left"><code>DIR</code></td><td align="left">表示目录</td></tr><tr><td align="left"><code>CHR</code></td><td align="left">表示字符类型</td></tr><tr><td align="left"><code>BLK</code></td><td align="left">块设备类型</td></tr><tr><td align="left"><code>UNIX</code></td><td align="left">UNIX 域套接字</td></tr><tr><td align="left"><code>FIFO</code></td><td align="left">先进先出 (FIFO) 队列</td></tr><tr><td align="left"><code>IPv4</code></td><td align="left">网际协议 (IP) 套接字</td></tr><tr><td align="left"><code>DEVICE</code></td><td align="left">指定磁盘的名称</td></tr><tr><td align="left"><code>SIZE</code></td><td align="left">文件的大小</td></tr><tr><td align="left"><code>NODE</code></td><td align="left">索引节点(文件在磁盘上的标识)</td></tr><tr><td align="left"><code>NAME</code></td><td align="left">打开文件的确切名称</td></tr><tr><td align="left"><code>REG</code></td><td align="left">常规文件</td></tr></tbody></table>
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="列出指定进程号所打开的文件"><a aria-hidden="true" tabindex="-1" href="#列出指定进程号所打开的文件"><span class="icon icon-link"></span></a>列出指定进程号所打开的文件</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token function">lsof</span> <span class="token parameter variable">-p</span> <span class="token variable">$pid</span>
</span></code></pre>
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="获取端口对应的进程-idpid"><a aria-hidden="true" tabindex="-1" href="#获取端口对应的进程-idpid"><span class="icon icon-link"></span></a>获取端口对应的进程 ID=>pid</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token function">lsof</span> <span class="token parameter variable">-i:9981</span> <span class="token parameter variable">-P</span> <span class="token parameter variable">-t</span> <span class="token parameter variable">-sTCP:LISTEN</span>
</span></code></pre>
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="列出打开文件的进程"><a aria-hidden="true" tabindex="-1" href="#列出打开文件的进程"><span class="icon icon-link"></span></a>列出打开文件的进程:</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token function">lsof</span> <span class="token variable">$filename</span>
</span></code></pre>
</div></div></div></div></div></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 Kenny Wang, All rights reserved.</footer></footer><script>
if(('onhashchange' in window) && ((typeof document.documentMode==='undefined') || document.documentMode==8)) {
window.onhashchange = function () {