(2)free详解 (每周一个linux命令系列)
(2)free详解 (每周一个linux命令系列)
linux命令 free详解
引言:今天的命令是用来看内存的free
free
换一个套路,我们先看man free中对free的描述:
Display amount of free and used memory in the system
翻译:显示系统中使用的和未用的内存数量
我们再来看一下命令执行结果
total used free shared buff/cache available
Mem: 16131568 8461796 1418932 848140 6250840 6352668
Swap: 8191996 24 8191972
man free中对各个表头的解释如下
free displays the total amount of free and used physical and swap
memory in the system, as well as the buffers and caches used by
the kernel. The information is gathered by parsing /proc/meminfo.
The displayed columns are:
total Total installed memory (MemTotal and SwapTotal in
/proc/meminfo)
used Used memory (calculated as total - free - buffers - cache)
free Unused memory (MemFree and SwapFree in /proc/meminfo)
shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo,
available on kernels 2.6.32, displayed as zero if not
available)
buffers
Memory used by kernel buffers (Buffers in /proc/meminfo)
cache Memory used by the page cache and slabs (Cached and Slab
in /proc/meminfo)
buff/cache
Sum of buffers and cache
available
Estimation of how much memory is available for starting
new applications, without swapping. Unlike the data pro‐
vided by the cache or free fields, this field takes into
account page cache and also that not all reclaimable mem‐
ory slabs will be reclaimed due to items being in use
(MemAvailable in /proc/meminfo, available on kernels 3.14,
emulated on kernels 2.6.27+, otherwise the same as free)
我们来分别解释一下(其实就是翻译一下),
free命令显示系统中所有使用的和未使用的物理内存和交换分区的数量(这里大概提一下,交换区作用是的当内存不够的时候,部分不常使用的信息被暂时存储到交换区,待使用的时候再放到内存中),以及内核使用的缓冲区和缓存(buffer和caches分不清的话,可以理解为buffer是一些放在内存中还没有刷到磁盘的缓存数据,而caches是从磁盘中读出到内存的数据。这里不展开介绍了),这些信息来源于解析 /proc/meminfo ,显示的属性如下:
- total 系统安装的总内存
- used 使用的内存 计算方法为:total - free - buffers - cache
- free 未使用的内存
- shared (最可能是)被tmpfs文件系统使用的内存 一般不会用到
- buffers buffers使用的内存数
- cache cache和slab使用的内存数(slab是linux下的一种内存分配机制,可以避免频繁的分配同类内存,即可以循环利用)
- buff/cache buffers和cache的和
- available 估计有多少内存在启动新的应用时可以被用到
接下来我们学习一下free可携带的参数
Options:
-b, --bytes show output in bytes 使用字节显示
-k, --kilo show output in kilobytes 使用kb显示
-m, --mega show output in megabytes 使用mb显示
-g, --giga show output in gigabytes 使用gb显示
--tera show output in terabytes 使用tb
-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 重复输出n次然后退出(每秒一次)
-w, --wide wide output buffers和cache会分开显示
--help display this help and exit 帮助
-V, --version output version information and exit 版本信息
常用命令运行结果如下:
free -h
total used free shared buff/cache available
Mem: 15G 8.1G 1.2G 836M 6.1G 6.0G
Swap: 7.8G 24K 7.8G
dev1:~$ free -s 5
total used free shared buff/cache available
Mem: 16131568 8507812 1217156 856332 6406600 6299660
Swap: 8191996 24 8191972
^C
dev1:~$ free -hs 5
total used free shared buff/cache available
Mem: 15G 8.1G 1.2G 836M 6.1G 6.0G
Swap: 7.8G 24K 7.8G
^C
dev1:~$ free -w
total used free shared buffers cache available
Mem: 16131568 8484328 1240332 856332 0 6406908 6323160
Swap: 8191996 24 8191972
dev1:~$ free -wh
total used free shared buffers cache available
Mem: 15G 8.1G 1.2G 836M 0B 6.1G 6.0G
Swap: 7.8G 24K 7.8G
free -s 5 -c 2 //五秒运行一次,一共运行两次就退出
total used free shared buff/cache available
Mem: 16131568 8535816 1179516 856364 6416236 6271488
Swap: 8191996 24 8191972
total used free shared buff/cache available
Mem: 16131568 8539412 1175796 856364 6416360 6267892
Swap: 8191996 24 8191972
其他的运行结果就不给了,给了的话就有点刷文章长度的嫌疑。大概说一下常用的结合用法吧
- -h 命令是比较常用的 可以与其他的-w -s -c配合使用
- -s 和-c是可以同时使用的 例如 free -s 5 -c 2 //五秒运行一次,一共运行两次
- --si 是需要和-b -k -m -g这些一起使用,不再以1024为进位标准而是1000
- 其他的请大家自由组合尝试吧
(2)free详解 (每周一个linux命令系列)的更多相关文章
- (5)ps详解 (每周一个linux命令系列)
(5)ps详解 (每周一个linux命令系列) linux命令 ps详解 引言:今天的命令是用来看进程状态的ps命令 ps 我们先看man ps ps - report a snapshot of t ...
- (4)top详解 (每周一个linux命令系列)
(4)top详解 (每周一个linux命令系列) linux命令 top详解 引言:今天的命令是用来看cpu信息的top top 我们先看man top top - display Linux pro ...
- (3)lscpu详解 (每周一个linux命令系列)
(3)lscpu详解 (每周一个linux命令系列) linux命令 lscpu详解 引言:今天的命令是用来看cpu信息的lscpu lscpu 我们先看man lscpu display infor ...
- (6)sudo命令详解(每周一个linux命令系列)
首先说句抱歉,最近事情比较复杂,停更了一阵子.我又回来啦 多用户管理 我们常用的windows个人系统虽然可以设置多用户,但是实际上是不可以多用户同时登陆的(这个我实验过,我以前用windows服务器 ...
- (7)awk命令(每周一个linux命令系列)
简介 awk是一个强大的文本分析工具,尤其是在应对格式化比较好的日志文件时,简单来说awk就是把文件逐行的读入,以空格为默认分隔符(也可以指定分隔符)将每行切片处理. 语法 awk [选项参数] 's ...
- 每周一个linux命令之---uptime详解
每周一个linux命令之---uptime详解 linux命令 uptime详解 引言:从今天开始,每周更新一个对程序员有用的linux命令,我真的没敢写每天一个,我怕我坚持不下去,每周一个还是可以的 ...
- 企业sudo权限规划详解 (实测一个堆命令搞定)
简述问题: 随着公司的服务器越来越多,人员流动性也开始与日俱增,以往管理服务器的陈旧思想应当摒弃,公司需要有 更好更完善的权限体系,经过多轮沟通和协商,公司一致决定重新整理规划权限体系 ...
- (11)nc命令(每周一个linux命令)
nc(netcat)实用程序几乎可用于所有涉及TCP或UDP的事情.它可以打开TCP连接,发送UDP数据包,监听任意TCP和UDP端口,进行端口扫描,处理IPv4和IPv6.与telnet不同,nc可 ...
- 【转载】每天一个Linux命令
目 录 每天一个linux命令(1) : ls 命令 每天一个linux命令(2) : cd 命令 每天一个linux命令(3) : pwd 命令 每天一个linux命令(4) : mkdi ...
随机推荐
- [转]git操作指南
[GIT上手篇]-1-基本操作(初始化仓库,添加.提交文件) 创建(初始化)一个GIT库 init 命令 说明:用于仓库的初始化 参数:--bare 创建一个纯仓库(不含缓存区和工作目录,服务器一般采 ...
- JAVA中的集合容器操作类
目录 JAVA中的集合容器操作类 List集合 ArrayList的操作方法说明 LinkedList Stack Set Map Queue 总结 JAVA中的集合容器操作类 Java容器类库总共分 ...
- JDK源码解析之Java SPI机制
1. spi 是什么 SPI全称Service Provider Interface,是Java提供的一套用来被第三方实现或者扩展的API,它可以用来启用框架扩展和替换组件. 系统设计的各个抽象,往往 ...
- 【Java POI】1、Java POI的使用
很多时候,一个软件应用程序需要生成Microsoft Excel文件格式的报告.有时,一个应用程序甚至希望将Excel文件作为输入数据.例如,一个公司开发的应用程序将财务部门需要所有输出生成自己的Ex ...
- 通过Eureka自带REST API强行剔除失效服务
1.确定需要强行剔除的服务 2.执行接口 方便复制: http://{ip}:{port}/eureka/apps/CONFIG-SERVER-TEST/tom:config-server-test: ...
- Linux常用基本命令:三剑客命令之-awk动作用法(1)
1,多个动作,怎么写? ghostwu@dev:~/linux/awk$ cat host.txt name ip地址 host1 192.168.1.1 host2 192.177.81.1 hos ...
- echarts2.0仪表盘
option = { backgroundColor: '#0e0b2a', tooltip : { formatter: "{a} <br/>{b} : {c}%" ...
- 网页布局设计css中单位px和em,rem的区别
国内的设计师大都喜欢用px,而国外的网站大都喜欢用em和rem,那么三者有什么区别,又各自有什么优劣呢? PX特点 1. IE无法调整那些使用px作为单位的字体大小: 2. 国外的大部分网站能够调整的 ...
- VSCode中怎么改变文件夹的图标
昨天更新了VSCode后我的文件夹图标莫名其妙的没有了,变成了下图这样 看着真的让我难受的头皮发麻,本来打代码就头发少,难道非要让我变成秃头,不可能不可能,所以我找了找怎么解决 来,各位看官上眼 如图 ...
- hosts 文件
各系统平台hosts文件存放路径 路径如下: Windows系统: C:\Windows\System32\drivers\etc\hosts Linux系统:/etc/hosts ...