Linux之free命令

一、介绍

free命令用于输出系统中空闲,已用的物理内存和虚拟内存(swap)、内核缓冲区

二、使用方法

语法:free [选项]
选项:
-k,-m,-g 以KB、MB、GB为存储单位对当前的内存使用情况输出
-h 以人类可读的方式输出,在数字后面加上存储单位 
-s 指定以秒为时间单位,持续输出当前系统内存的使用状况
-t 输出物理内存加上虚拟内存的总和

三、案例

1.查看内存的使用状况

[root@pingzimo ~]# free -hm
total used free shared buffers cached
Mem: 1.8G 151M 1.7G 152K 11M 53M
-/+ buffers/cache: 86M 1.7G 
Swap: 0B 0B 0B

第二表示(mem)
total:总计物理内存的大小
used:已使用内存大小
free:可用的内存大小
shared:多个进程共享的内存总额 
buffers/cache:磁盘缓存的大小
内核层面的内存使用量
第三行(buffers/cache)
表示应用程序使用的层面
used:已用大小
free:可用大小
第四行是(swap)
swap的使用量(swap为虚拟内存)

2.每隔3秒输出当前系统的内存使用情况,并输出当前系统的物理内存和虚拟内存之和 

 [root@pingzimo ~]# free -tmh -s 3 
             total       used       free     shared    buffers     cached
Mem:          1.8G       151M       1.7G       152K        11M        53M
-/+ buffers/cache:        86M       1.7G 
Swap:           0B         0B         0B 
Total:        1.8G       151M       1.7G 

             total       used       free     shared    buffers     cached
Mem:          1.8G       151M       1.7G       152K        11M        53M
-/+ buffers/cache:        86M       1.7G 
Swap:           0B         0B         0B 
Total:        1.8G       151M       1.7G 

3.清除系统中的缓存(cache)

1.清除页面缓存
[root@pingzimo ~]# sync ; echo 1 > /proc/sys/vm/drop_caches 
2.清除目录项和inode
[root@pingzimo ~]# sync ; echo 2 > /proc/sys/vm/drop_caches 
3.清除页面缓存,目录项和inode 
[root@pingzimo ~]# sync ; echo 3 > /proc/sys/vm/drop_caches 

  

原文地址:https://www.cnblogs.com/pingzhe/p/8669383.html