(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 ...
随机推荐
- c语言中阶乘的精确值
对于大数的操作,可能超出int,甚至long的表示范围,对此,可以使用数组来存储大数,下列代码为求1000以内数的阶乘的代码,代码如下: #include <stdio.h> #inclu ...
- JS截取字符串substr 和 substring方法的区别
substr 方法 返回一个从指定位置开始的指定长度的子字符串. stringvar.substr(start [, length ]) 参数 stringvar 必选项.要提取子字符串的字符串文字或 ...
- 使用 New Relic 监控接口服务性能 (APM)
偶然看到贴子在使用[Rails API] 使用这个APM监控,今天试了下.NET IIS环境下,配置一路NEXT即可. 主要指标 服务响应时间 Segment SQL执行时间 安全问题 1.走HTTP ...
- 设置div背景透明的CSS样式
div背景透明样式: 样式代码: .alert{filter:alpha(opacity=100); /* IE */ -moz-opacity:1.0; /* Moz + FF */ opacity ...
- sql server: Graphs, Trees, Hierarchies and Recursive Queries
--------------------------------------------------------------------- -- Chapter 09 - Graphs, Trees, ...
- CSS元素(文本、图片)水平垂直居中方法
1.text-align:center; 2.margin:0 auto; 3.display:inline-block; + text-align:center; 4.position:relati ...
- 【代码笔记】Web-手机端的meta
一,天猫 <title>天猫触屏版</title> <meta content="text/html; charset=utf-8" http-equ ...
- 我的Java之旅 第一课 开发环境准备
1.JDK JDK(Java Development Kit) 是 Java 语言的软件开发工具包(SDK). SE(J2SE),standard edition,标准版,是我们通常用的一个版本,从J ...
- Salesforce的翻译工作台
翻译工作台 Salesforce提供了翻译工作台.在这里管理员可以对各种数据进行翻译设置,包括对象信息.字段信息.验证规则.错误信息等. 翻译工作台集中了翻译的内容,从而使得管理员或开发者不需要在其他 ...
- (后端)org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1,actual 0
两种方案: 用queryForList方法替换queryForObject或者queryForMap,因为这两个方法必须要有值,不能为空. 把这个异常捕获,用try/catch. 这个查询的结果是nu ...