首頁·終端機命令

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