首页·终端命令

free

进程与系统

用法

free -h

在 Linux 上统计还剩多少内存和交换区;该看的一列是 available 而不是 free,因为缓存需要时会还回来,而 macOS 根本没有 free(用 vm_stat)。

常用选项

选项含义
-hHuman units, so Gi and Mi instead of raw kibibytes.
-m / -gForce mebibytes / gibibytes.
-s 5Repeat every five seconds until Ctrl+C.
-tAdd a total row for RAM plus swap.
-wWide output that separates buffers from cache.

示例

free -h

Read the available column: that is what a new program can actually get.

free -m -s 5

Watch memory every five seconds while a job runs.

看什么在跑、什么在吃机器。先弄清是什么,再决定杀不杀。

怎么看

  • 方括号 [ ] 表示这部分可以不写。
  • 省略号 … 表示可以写多个。
  • 选项区分大小写——有些命令里 -r 和 -R 不是一回事。

常见问题

Q. free 是做什么的?

在 Linux 上统计还剩多少内存和交换区;该看的一列是 available 而不是 free,因为缓存需要时会还回来,而 macOS 根本没有 free(用 vm_stat)。

Q. 怎么写?

free -h —— 方括号表示可以省略的部分。

Q. 值得记的选项有几个?

这里列了 5 个,完整列表在 man free。这条命令属于进程与系统。

相关命令

man 手册: man free