如何在 Linux 系统中判断安装、使用了多少内存 | Linux 中国

找不到分类 evilven 3周前 (08-28) 29次浏览 已收录 0个评论 扫描二维码
如何在 Linux 系统中判断安装、使用了多少内存 | Linux 中国

有几个命令可以报告在 Linux 系统上安装和使用了多少内存。根据你使用的命令,你可能会被细节淹没,也可能获得快速简单的答案。

— Sandra Henry-stocker


在 Linux 系统中有很多种方法获取有关安装了多少内存的信息及查看多少内存正在被使用。有些命令提供了大量的细节,而其他命令提供了简洁但不一定易于理解的答案。在这篇文章中,我们将介绍一些查看内存及其使用状态的有用的工具。

在我们开始之前,让我们先来回顾一些基础知识。物理内存和虚拟内存并不是一回事。后者包括配置为交换空间的磁盘空间。交换空间可能包括为此目的特意留出来的分区,以及在创建新的交换分区不可行时创建的用来增加可用交换空间的文件。有些 Linux 命令会提供关于两者的信息。

当物理内存占满时,交换空间通过提供可以用来存放内存中非活动页的磁盘空间来扩展内存。

/proc/kcore 是在内存管理中起作用的一个文件。这个文件看上去是个普通文件(虽然非常大),但它并不占用任何空间。它就像其他 /proc 下的文件一样是个虚拟文件。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">ls</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">l </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">proc</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">kcore</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">r</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">--------.</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> root root </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">140737477881856</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Jan</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">28</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">12</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">59</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">proc</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">kcore</span></code></section></li>
</ol>

有趣的是,下面查询的两个系统并没有安装相同大小的内存,但 /proc/kcore 的大小却是相同的。第一个系统安装了 4 GB 的内存,而第二个系统安装了 6 GB。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">system1$ </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">ls</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">l </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">proc</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">kcore</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">r</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">--------.</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> root root </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">140737477881856</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Jan</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">28</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">12</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">59</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">proc</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">kcore</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">system2$ </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">ls</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">l </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">proc</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">kcore</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">r</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">--------</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">  </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> root root </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">140737477881856</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Feb</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">  </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">5</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">13</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">00</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">proc</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">kcore</span></code></section></li>
</ol>

一种不靠谱的解释说这个文件代表可用虚拟内存的大小(没准要加 4 KB),如果这样,这些系统的虚拟内存可就是 128TB 了!这个数字似乎代表了 64 位系统可以寻址多少内存,而不是当前系统有多少可用内存。在命令行中计算 128 TB 和这个文件大小加上 4 KB 很容易。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">expr</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1024</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> * </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1024</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> * </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1024</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> * </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1024</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> * </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">128</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">140737488355328</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">expr</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1024</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> * </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1024</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> * </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1024</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> * </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1024</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> * </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">128</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">+</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4096</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">140737488359424</span></code></section></li>
</ol>

另一个用来检查内存的更人性化的命令是 free。它会给出一个易于理解的内存报告。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ free</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">              total        used        free      shared  buff</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">cache   available</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Mem</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">        </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6102476</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">      </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">812244</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4090752</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">       </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">13112</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1199480</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4984140</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Swap</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">       </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2097148</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2097148</span></code></section></li>
</ol>

使用 -g 选项,free 会以 GB 为单位返回结果。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ free </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">g</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">              total        used        free      shared  buff</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">cache   available</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Mem</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">              </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">5</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">3</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Swap</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">             </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1</span></code></section></li>
</ol>

使用 -t 选项,free 会显示与无附加选项时相同的值(不要把 -t 选项理解成 TB),并额外在输出的底部添加一行总计数据。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ free </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">t</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">              total        used        free      shared  buff</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">cache   available</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Mem</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">        </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6102476</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">      </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">812408</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4090612</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">       </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">13112</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1199456</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4983984</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Swap</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">       </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2097148</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2097148</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Total</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">      </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">8199624</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">      </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">812408</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6187760</span></code></section></li>
</ol>

当然,你也可以选择同时使用两个选项。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ free </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">tg</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">              total        used        free      shared  buff</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">cache   available</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Mem</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">              </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">5</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">3</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Swap</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">             </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Total</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">            </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">7</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">5</span></code></section></li>
</ol>

如果你尝试用这个报告来解释“这个系统安装了多少内存?”,你可能会感到失望。上面的报告就是在前文说的装有 6 GB 内存的系统上运行的结果。这并不是说这个结果是错的,这就是系统对其可使用的内存的看法。

free 命令也提供了每隔 X 秒刷新显示的选项(下方示例中 X 为 10)。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ free </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">s </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">10</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">              total        used        free      shared  buff</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">cache   available</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Mem</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">        </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6102476</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">      </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">812280</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4090704</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">       </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">13112</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1199492</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4984108</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Swap</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">       </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2097148</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2097148</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">              total        used        free      shared  buff</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">cache   available</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Mem</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">        </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6102476</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">      </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">812260</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4090712</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">       </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">13112</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1199504</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4984120</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Swap</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">       </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2097148</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2097148</span></code></section></li>
</ol>

使用 -l 选项,free 命令会提供高低内存使用信息。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ free </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">l</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">              total        used        free      shared  buff</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">cache   available</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Mem</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">        </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6102476</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">      </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">812376</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4090588</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">       </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">13112</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1199512</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4984000</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Low</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">        </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6102476</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2011888</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4090588</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">High</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">             </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Swap</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">       </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2097148</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">     </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2097148</span></code></section></li>
</ol>

查看内存的另一个选择是 /proc/meminfo 文件。像 /proc/kcore 一样,这也是一个虚拟文件,它可以提供关于安装或使用了多少内存以及可用内存的报告。显然,空闲内存和可用内存并不是同一回事。MemFree 看起来代表未使用的 RAM。MemAvailable 则是对于启动新程序时可使用的内存的一个估计。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">head</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">3</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">proc</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">meminfo</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">MemTotal</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6102476</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> kB</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">MemFree</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4090596</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> kB</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">MemAvailable</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4984040</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> kB</span></code></section></li>
</ol>

如果只想查看内存总计,可以使用下面的命令之一:

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ awk </span><span class="str" style="overflow-wrap: break-word;color: rgb(101, 176, 66);">'/MemTotal/ {print $2}'</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">proc</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">meminfo</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6102476</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">grep</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">MemTotal</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">proc</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">meminfo</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">MemTotal</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6102476</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> kB</span></code></section></li>
</ol>

DirectMap 将内存信息分为几类。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">grep</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">DirectMap</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">proc</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">meminfo</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">DirectMap4k</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">213568</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> kB</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">DirectMap2M</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6076416</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> kB</span></code></section></li>
</ol>

DirectMap4k 代表被映射成标准 4 k 页的内存大小,DirectMap2M 则显示了被映射为 2 MB 的页的内存大小。

getconf 命令将会提供比我们大多数人想要看到的更多的信息。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ getconf </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">a </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">|</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">more</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">LINK_MAX </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">65000</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_POSIX_LINK_MAX </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">65000</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">MAX_CANON </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">255</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_POSIX_MAX_CANON </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">255</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">MAX_INPUT </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">255</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_POSIX_MAX_INPUT </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">255</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">NAME_MAX </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">255</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_POSIX_NAME_MAX </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">255</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">PATH_MAX </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4096</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_POSIX_PATH_MAX </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4096</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">PIPE_BUF </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4096</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_POSIX_PIPE_BUF </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4096</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">SOCK_MAXBUF</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_POSIX_ASYNC_IO</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_POSIX_CHOWN_RESTRICTED </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_POSIX_NO_TRUNC </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_POSIX_PRIO_IO</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_POSIX_SYNC_IO</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_POSIX_VDISABLE </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">ARG_MAX </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2097152</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">ATEXIT_MAX </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2147483647</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">CHAR_BIT </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">8</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">CHAR_MAX </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">127</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">--</span><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">More</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">--</span></code></section></li>
</ol>

使用类似下面的命令来将其输出精简为指定的内容,你会得到跟前文提到的其他命令相同的结果。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ getconf </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">a </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">|</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">grep</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> PAGES </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">|</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> awk </span><span class="str" style="overflow-wrap: break-word;color: rgb(101, 176, 66);">'BEGIN {total = 1} {if (NR == 1 || NR == 3) total *=$NF} END {print total / 1024" kB"}'</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6102476</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> kB</span></code></section></li>
</ol>

上面的命令通过将下方输出的第一行和最后一行的值相乘来计算内存。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">PAGESIZE                           </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4096</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">    </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"><==</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_AVPHYS_PAGES                      </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1022511</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">_PHYS_PAGES                        </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1525619</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"><==</span></code></section></li>
</ol>

自己动手计算一下,我们就知道这个值是怎么来的了。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">expr</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">4096</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> * </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1525619</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1024</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6102476</span></code></section></li>
</ol>

显然值得为以上的指令之一设置个 alias

另一个具有非常易于理解的输出的命令是 top 。在 top 输出的前五行,你可以看到一些数字显示多少内存正被使用。

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">top</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">top</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">15</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">36</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">38</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> up </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">8</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> days</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">37</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">2</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">users</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> load average</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0.00</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0.00</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0.00</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Tasks</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">266</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> total</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> running</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">265</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> sleeping</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> stopped</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> zombie</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">%</span><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Cpu</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">(</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">s</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">):</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0.2</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> us</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0.4</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> sy</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0.0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> ni</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">99.4</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">id</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0.0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> wa</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0.0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> hi</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0.0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> si</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0.0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> st</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">MiB</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Mem</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">3244.8</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> total</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">377.9</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> free</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1826.2</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> used</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1040.7</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> buff</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">/</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">cache</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">MiB</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Swap</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">:</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">3536.0</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> total</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">3535.7</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> free</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">,</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">0.3</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> used</span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">.</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">1126.1</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> avail </span><span class="typ" style="overflow-wrap: break-word;color: rgb(137, 189, 255);">Mem</span></code></section></li>
</ol>

最后一个命令将会以一个非常简洁的方式回答“系统安装了多少内存?”:

<ol class="linenums list-paddingleft-2" style="margin-left: 2em;margin-right: 2em;">
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">$ </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">sudo</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> dmidecode </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">-</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">t </span><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">17</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">|</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="kwd" style="overflow-wrap: break-word;color: rgb(226, 137, 100);">grep</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="str" style="overflow-wrap: break-word;color: rgb(101, 176, 66);">"Size.*MB"</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> </span><span class="pun" style="overflow-wrap: break-word;color: rgb(184, 255, 184);">|</span><span class="pln" style="overflow-wrap: break-word;color: rgb(184, 255, 184);"> awk </span><span class="str" style="overflow-wrap: break-word;color: rgb(101, 176, 66);">'{s+=$2} END {print s / 1024 "GB"}'</span></code></section></li>
<li><section style="overflow-wrap: break-word;width: 1200px;max-width: 1200px !important;"><code style="overflow-wrap: break-word;background: none;color: rgb(33, 150, 243);line-height: 1.2em;padding-left: 10px !important;border-radius: 0px !important;margin-top: 1em !important;margin-bottom: 1em !important;border-width: initial !important;border-style: none !important;border-color: initial !important;"><span class="lit" style="overflow-wrap: break-word;color: rgb(51, 135, 204);">6GB</span></code></section></li>
</ol>

取决于你想要获取多少细节,Linux 系统提供了许多用来查看系统安装内存以及使用/空闲内存的选择。


via: https://www.networkworld.com/article/3336174/linux/how-much-memory-is-installed-and-being-used-on-your-linux-systems.html

作者:Sandra Henry-Stocker[2] 选题:lujun9972 译者:leommxj 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

如何在 Linux 系统中判断安装、使用了多少内存 | Linux 中国


Hacking For Fun , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如何在 Linux 系统中判断安装、使用了多少内存 | Linux 中国
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址