linux 查看内存
一、背景
在使用Linux的过程中,我们经常会遇到查看Linux的内存使用情况。
二、解决方法
使用free命令。
free命令的使用方法如下:
[root@localhost topsec]# free --help
Usage:
free [options]
free [options]
Options:
-b, --bytes show output in bytes //以字节(byte)的单位显示内存的使用状况
-k, --kilo show output in kilobytes //以KB的单位显示内存的使用状况
-m, --mega show output in megabytes //以M的单位显示内存的使用状况
-g, --giga show output in gigabytes // 以G的单位显示内存的使用状况
--tera show output in terabytes //以T的单位显示内存的使用状况
-h, --human show human-readable output // 以通俗易懂的方式显示内存的使用状况
--si use powers of 1000 not 1024 //以1000 代替1024的刻度显示内存
-l, --lohi show detailed low and high memory statistics //显示最低内存和最高内存
-t, --total show total for RAM + swap //显示内存与交换区的和
-s N, --seconds N repeat printing every N seconds //每隔s 秒运行一次free
-c N, --count N repeat printing N times, then exit //运行N次并退出
-w, --wide wide output //分开显示
-b, --bytes show output in bytes //以字节(byte)的单位显示内存的使用状况
-k, --kilo show output in kilobytes //以KB的单位显示内存的使用状况
-m, --mega show output in megabytes //以M的单位显示内存的使用状况
-g, --giga show output in gigabytes // 以G的单位显示内存的使用状况
--tera show output in terabytes //以T的单位显示内存的使用状况
-h, --human show human-readable output // 以通俗易懂的方式显示内存的使用状况
--si use powers of 1000 not 1024 //以1000 代替1024的刻度显示内存
-l, --lohi show detailed low and high memory statistics //显示最低内存和最高内存
-t, --total show total for RAM + swap //显示内存与交换区的和
-s N, --seconds N repeat printing every N seconds //每隔s 秒运行一次free
-c N, --count N repeat printing N times, then exit //运行N次并退出
-w, --wide wide output //分开显示
--help display this help and exit //显示free命令的使用方法
-V, --version output version information and exit // 显示free命令的版本
-V, --version output version information and exit // 显示free命令的版本
For more details see free(1).
[root@localhost topsec]#
[root@localhost topsec]#
三、例子
1、查看所有内存,以M的单位显示
[root@localhost topsec]# free -m
total used free shared buff/cache available
Mem: 2832 843 1149 42 840 1729
Swap: 3071 0 3071
[root@localhost topsec]#
total used free shared buff/cache available
Mem: 2832 843 1149 42 840 1729
Swap: 3071 0 3071
[root@localhost topsec]#
其中可以看出内存总量为2832M,已经使用843M。
四、其他命令
top 命令。这里就不说明了,下次吧。