温馨提示×

如何查看linux swap大小

小樊
39
2026-10-24 11:05:48
栏目: 智能运维

在 Linux 中,可以通过以下几种常用方法查看 swap(交换分区/交换文件)大小:


方法一:free 命令(最常用)

free -h

输出示例:

              total        used        free      shared  buff/cache   available
Mem:           7.7G        2.1G        3.2G        123M        2.4G        5.1G
Swap:          2.0G          0B        2.0G
  • Swap 一行显示 swap 总大小、已用和空闲

方法二:swapon 命令

swapon --show

或

swapon -s

输出示例:

NAME      TYPE      SIZE USED PRIO
/dev/sda2 partition   2G   0B   -2
  • 会列出所有 swap 设备及其大小

方法三:查看 /proc/swaps

cat /proc/swaps

输出示例:

Filename                Type        Size    Used    Priority
/dev/sda2               partition   2097148 0       -2
  • Size 单位为 KB

方法四:top / htop

  • 在 top 中按 1 或查看顶部摘要
  • htop 底部状态栏直接显示 Swap 大小

方法五:查看磁盘分区(针对 swap 分区)

lsblk

或

fdisk -l

可看到类型为 swap 的分区及其大小。


✅ 推荐:日常快速查看用

free -h

或

swapon --show

如果你是想调整 swap 大小或新增 swap 文件,也可以告诉我。

0 踩