(2)free详解 (每周一个linux命令系列)

linux命令 free详解


引言:今天的命令是用来看内存的free

free

换一个套路,我们先看man free中对free的描述:


  1. Display amount of free and used memory in the system

翻译:显示系统中使用的和未用的内存数量

我们再来看一下命令执行结果

  1. total used free shared buff/cache available
  2. Mem: 16131568 8461796 1418932 848140 6250840 6352668
  3. Swap: 8191996 24 8191972

man free中对各个表头的解释如下

  1. free displays the total amount of free and used physical and swap
  2. memory in the system, as well as the buffers and caches used by
  3. the kernel. The information is gathered by parsing /proc/meminfo.
  4. The displayed columns are:
  5. total Total installed memory (MemTotal and SwapTotal in
  6. /proc/meminfo)
  7. used Used memory (calculated as total - free - buffers - cache)
  8. free Unused memory (MemFree and SwapFree in /proc/meminfo)
  9. shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo,
  10. available on kernels 2.6.32, displayed as zero if not
  11. available)
  12. buffers
  13. Memory used by kernel buffers (Buffers in /proc/meminfo)
  14. cache Memory used by the page cache and slabs (Cached and Slab
  15. in /proc/meminfo)
  16. buff/cache
  17. Sum of buffers and cache
  18. available
  19. Estimation of how much memory is available for starting
  20. new applications, without swapping. Unlike the data pro
  21. vided by the cache or free fields, this field takes into
  22. account page cache and also that not all reclaimable mem
  23. ory slabs will be reclaimed due to items being in use
  24. (MemAvailable in /proc/meminfo, available on kernels 3.14,
  25. emulated on kernels 2.6.27+, otherwise the same as free)

我们来分别解释一下(其实就是翻译一下),

free命令显示系统中所有使用的和未使用的物理内存和交换分区的数量(这里大概提一下,交换区作用是的当内存不够的时候,部分不常使用的信息被暂时存储到交换区,待使用的时候再放到内存中),以及内核使用的缓冲区和缓存(buffer和caches分不清的话,可以理解为buffer是一些放在内存中还没有刷到磁盘的缓存数据,而caches是从磁盘中读出到内存的数据。这里不展开介绍了),这些信息来源于解析 /proc/meminfo ,显示的属性如下:

  1. - total 系统安装的总内存
  2. - used 使用的内存 计算方法为:total - free - buffers - cache
  3. - free 未使用的内存
  4. - shared (最可能是)被tmpfs文件系统使用的内存 一般不会用到
  5. - buffers buffers使用的内存数
  6. - cache cacheslab使用的内存数(slablinux下的一种内存分配机制,可以避免频繁的分配同类内存,即可以循环利用)
  7. - buff/cache bufferscache的和
  8. - available 估计有多少内存在启动新的应用时可以被用到

接下来我们学习一下free可携带的参数

  1. Options:
  2. -b, --bytes show output in bytes 使用字节显示
  3. -k, --kilo show output in kilobytes 使用kb显示
  4. -m, --mega show output in megabytes 使用mb显示
  5. -g, --giga show output in gigabytes 使用gb显示
  6. --tera show output in terabytes 使用tb
  7. -h, --human show human-readable output 使用人类易读的方式
  8. --si use powers of 1000 not 1024 使用一千字节计数
  9. -l, --lohi show detailed low and high memory statistics 显示最高最低的统计信息
  10. -t, --total show total for RAM + swap 显示物理内存和交换区总数
  11. -s N, --seconds N repeat printing every N seconds 每几分钟重复显示一次
  12. -c N, --count N repeat printing N times, then exit 重复输出n次然后退出(每秒一次)
  13. -w, --wide wide output bufferscache会分开显示
  14. --help display this help and exit 帮助
  15. -V, --version output version information and exit 版本信息

常用命令运行结果如下:

  1. free -h
  2. total used free shared buff/cache available
  3. Mem: 15G 8.1G 1.2G 836M 6.1G 6.0G
  4. Swap: 7.8G 24K 7.8G
  5. dev1:~$ free -s 5
  6. total used free shared buff/cache available
  7. Mem: 16131568 8507812 1217156 856332 6406600 6299660
  8. Swap: 8191996 24 8191972
  9. ^C
  10. dev1:~$ free -hs 5
  11. total used free shared buff/cache available
  12. Mem: 15G 8.1G 1.2G 836M 6.1G 6.0G
  13. Swap: 7.8G 24K 7.8G
  14. ^C
  15. dev1:~$ free -w
  16. total used free shared buffers cache available
  17. Mem: 16131568 8484328 1240332 856332 0 6406908 6323160
  18. Swap: 8191996 24 8191972
  19. dev1:~$ free -wh
  20. total used free shared buffers cache available
  21. Mem: 15G 8.1G 1.2G 836M 0B 6.1G 6.0G
  22. Swap: 7.8G 24K 7.8G
  23. free -s 5 -c 2 //五秒运行一次,一共运行两次就退出
  24. total used free shared buff/cache available
  25. Mem: 16131568 8535816 1179516 856364 6416236 6271488
  26. Swap: 8191996 24 8191972
  27. total used free shared buff/cache available
  28. Mem: 16131568 8539412 1175796 856364 6416360 6267892
  29. Swap: 8191996 24 8191972

其他的运行结果就不给了,给了的话就有点刷文章长度的嫌疑。大概说一下常用的结合用法吧

  1. -h 命令是比较常用的 可以与其他的-w -s -c配合使用
  2. -s 和-c是可以同时使用的 例如 free -s 5 -c 2 //五秒运行一次,一共运行两次
  3. --si 是需要和-b -k -m -g这些一起使用,不再以1024为进位标准而是1000
  4. 其他的请大家自由组合尝试吧

(2)free详解 (每周一个linux命令系列)的更多相关文章

  1. (5)ps详解 (每周一个linux命令系列)

    (5)ps详解 (每周一个linux命令系列) linux命令 ps详解 引言:今天的命令是用来看进程状态的ps命令 ps 我们先看man ps ps - report a snapshot of t ...

  2. (4)top详解 (每周一个linux命令系列)

    (4)top详解 (每周一个linux命令系列) linux命令 top详解 引言:今天的命令是用来看cpu信息的top top 我们先看man top top - display Linux pro ...

  3. (3)lscpu详解 (每周一个linux命令系列)

    (3)lscpu详解 (每周一个linux命令系列) linux命令 lscpu详解 引言:今天的命令是用来看cpu信息的lscpu lscpu 我们先看man lscpu display infor ...

  4. (6)sudo命令详解(每周一个linux命令系列)

    首先说句抱歉,最近事情比较复杂,停更了一阵子.我又回来啦 多用户管理 我们常用的windows个人系统虽然可以设置多用户,但是实际上是不可以多用户同时登陆的(这个我实验过,我以前用windows服务器 ...

  5. (7)awk命令(每周一个linux命令系列)

    简介 awk是一个强大的文本分析工具,尤其是在应对格式化比较好的日志文件时,简单来说awk就是把文件逐行的读入,以空格为默认分隔符(也可以指定分隔符)将每行切片处理. 语法 awk [选项参数] 's ...

  6. 每周一个linux命令之---uptime详解

    每周一个linux命令之---uptime详解 linux命令 uptime详解 引言:从今天开始,每周更新一个对程序员有用的linux命令,我真的没敢写每天一个,我怕我坚持不下去,每周一个还是可以的 ...

  7. 企业sudo权限规划详解 (实测一个堆命令搞定)

    简述问题:         随着公司的服务器越来越多,人员流动性也开始与日俱增,以往管理服务器的陈旧思想应当摒弃,公司需要有 更好更完善的权限体系,经过多轮沟通和协商,公司一致决定重新整理规划权限体系 ...

  8. (11)nc命令(每周一个linux命令)

    nc(netcat)实用程序几乎可用于所有涉及TCP或UDP的事情.它可以打开TCP连接,发送UDP数据包,监听任意TCP和UDP端口,进行端口扫描,处理IPv4和IPv6.与telnet不同,nc可 ...

  9. 【转载】每天一个Linux命令

    目  录 每天一个linux命令(1)  : ls 命令 每天一个linux命令(2)  : cd 命令 每天一个linux命令(3)  : pwd 命令 每天一个linux命令(4)  : mkdi ...

随机推荐

  1. .net Framework 源代码 · ScrollViewer

    本文是分析 .net Framework 源代码的系列,主要告诉大家微软做 ScrollViewer 的思路,分析很简单 看完本文,可以学会如何写一个 ScrollViewer ,如何定义一个 ISc ...

  2. ViewModel处理View相关事件的多种方式(非技术贴,仅学习总结)

    众所周知,在UWP中,微软为我们提供了一种新的绑定方式:x:bind,它是基于编译时的绑定.在性能方面,运行时绑定Binding与它相比还是有些逊色的.因此针对一些确定的.不需要变更的数据,我们完全有 ...

  3. CSS如何让不相等的字符上下对齐

    最后效果: <div class="main"> <span style="font-size:12px;"><dl class= ...

  4. DOM之城市二级联动

    1.HTML内容 <select id="province"> <option>请选择</option> <option>山东省&l ...

  5. python中的清屏函数

    一:cmd中python的清屏函数 import os os.system("cls") cmd中演示 1.在cmd中输入命令行: 2.执行后: 3.为什么会遗留一个0? 因为函数 ...

  6. 【代码笔记】Web-ionic-列表

    一,效果图. 二,index.html代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8& ...

  7. Python 基于Python实现批量创建目录

    基于Python实现批量创建目录 by:授客QQ:1033553122 测试环境: Python版本:Python 2.7   代码实践 #!/usr/bin/env python # -*- cod ...

  8. OpenCV 填充(ROI)+模糊操作

    1.ROI 操作 src = cv.imread('./1.jpg') cv.imshow('src',src) dst = src[40:240,100:300] gray = cv.cvtColo ...

  9. CSS模糊效果及其兼容方法

    今天在整理IE滤镜时网站访问这里,居然找到模糊滤镜blur(),感觉太不可思议了,想不到IE居然会有这么多种滤镜效果,这基本上是模仿PS的.今天的重点是模糊滤镜 CSS模糊效果及其兼容方法 实例 兼容 ...

  10. 在Emacs中使用git操作

    在Emacs中使用git操作 1.安装 magit 插件 2.安装后开始使用 3.使用方法: . 使用 M-x:magit-status 打开当前仓库查看基本信息 .使用 ? 键查看magit命令绑定 ...