linux查看内存命令---free

free

作用:
Linux free命令用于显示内存状态。
free指令会显示内存的使用情况,包括实体内存,虚拟的交换文件内存,共享内存区段,以及系统核心使用的缓冲区等。

格式

free 【选项】 参数

如果没有参数的情况下,"free"命令显示内存的使用信息。默认按照k(b)的计数单位统计。

[root@linus ~]# free
              total        used        free      shared  buff/cache   available
Mem:        1867048      314712     1090716        9356      461620     1338224
Swap:       2097148           0     2097148

其中各项解释:
Mem:内存
Swap:交换分区
total:表示 总计物理内存的大小。(total=used+free)
used:表示 已使用多少。
free:表示 可用内存多少。
Shared:表示多个进程共享的内存总额。
Buffers/cached:表示 磁盘缓存的大小
available:剩余可用内存

在linux中,使用man手册,–help选项等都可以查看命令的选项,以–help为例

[root@linus ~]# free --help

Usage:
 free [options]

Options:
 -b, --bytes         show output in bytes
 -k, --kilo          show output in kilobytes
 -m, --mega          show output in megabytes
 -g, --giga          show output in gigabytes
     --tera          show output in terabytes
 -h, --human         show human-readable output
     --si            use powers of 1000 not 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	
 -c N, --count N     repeat printing N times, then exit	
 -w, --wide          wide output						
 
     --help     display this help and exit				
 -V, --version  output version information and exit		

For more details see free(1).

常用选项

-b :以Byte为单位显示内存使用情况。
-k :以KB为单位显示内存使用情况。
-m :以MB为单位显示内存使用情况。
-g:以GB为单位显示内容使用情况。
-h :以合适的单位显示内存使用情况,在(byte,kb,mb,gb,tb)中选择最合适的单位。
-l:显示高低内存的利用率。
-t:显示linux的全部内存。
-s N:表示每隔N秒打印一次内存信息,直到用ctrl+c结束或ctrl+z挂起。
-c N:表示重复打印内存信息N次
-V :显示版本信息

简单应用

[root@linus ~]# free -k			#以Byte为单位显示内存使用信息
              total        used        free      shared  buff/cache   available
Mem:        1867048      314204     1091164        9356      461680     1338684
Swap:       2097148           0     2097148
[root@linus ~]# free -b			#以KB为单位显示内存使用情况
              total        used        free      shared  buff/cache   available
Mem:     1911857152   321617920  1117478912     9580544   472760320  1370939392
Swap:    2147479552           0  2147479552
[root@linus ~]# free -m			#以MB为单位显示内存使用情况
              total        used        free      shared  buff/cache   available
Mem:           1823         306        1065           9         450        1307
Swap:          2047           0        2047
[root@linus ~]# free -h			#以合适的单位显示内存使用情况
              total        used        free      shared  buff/cache   available
Mem:           1.8G        306M        1.0G        9.1M        450M        1.3G
Swap:          2.0G          0B        2.0G
[root@linus ~]# free -l			#显示高低内存的利用率
              total        used        free      shared  buff/cache   available
Mem:        1867048      314456     1090900        9356      461692     1338432
Low:        1867048      776148     1090900
High:             0           0           0
Swap:       2097148           0     2097148
[root@linus ~]# free -t			#显示linux的全部内存
              total        used        free      shared  buff/cache   available
Mem:        1867048      314300     1091040        9356      461708     1338572
Swap:       2097148           0     2097148
Total:      3964196      314300     3188188
[root@linus ~]# free -s 1		#每隔1秒打印一次内存信息,打印了四次之后,将进程挂起
              total        used        free      shared  buff/cache   available
Mem:        1867048      314828     1090512        9356      461708     1338044
Swap:       2097148           0     2097148

              total        used        free      shared  buff/cache   available
Mem:        1867048      314844     1090496        9356      461708     1338028
Swap:       2097148           0     2097148

              total        used        free      shared  buff/cache   available
Mem:        1867048      314844     1090496        9356      461708     1338028
Swap:       2097148           0     2097148

              total        used        free      shared  buff/cache   available
Mem:        1867048      314844     1090496        9356      461708     1338028
Swap:       2097148           0     2097148

^Z
[8]+  已停止               free -s 1
[root@linus ~]# free -c 2			#打印内存信息两次
              total        used        free      shared  buff/cache   available
Mem:        1867048      315712     1089636        9356      461700     1337168
Swap:       2097148           0     2097148

              total        used        free      shared  buff/cache   available
Mem:        1867048      315712     1089636        9356      461700     1337168
Swap:       2097148           0     2097148

其余还有一些组合用法,例如:

[root@linus ~]# free -h -s 2 -c 2		#以适合的单位打印,每隔两秒打印一次,共两次
              total        used        free      shared  buff/cache   available
Mem:           1.8G        308M        1.0G        9.1M        450M        1.3G
Swap:          2.0G          0B        2.0G

              total        used        free      shared  buff/cache   available
Mem:           1.8G        308M        1.0G        9.1M        450M        1.3G
Swap:          2.0G          0B        2.0G
发布了14 篇原创文章 · 获赞 4 · 访问量 528

猜你喜欢

转载自blog.csdn.net/qq_42534026/article/details/103834534