[Translated] Linux free Command C Display Free and used Memory in the System

This commit is contained in:
geekpi 2014-01-02 02:14:39 +00:00
parent 6a23535b47
commit 2cb4e5a8ec
2 changed files with 92 additions and 96 deletions

View File

@ -1,96 +0,0 @@
Translating---------------------geekpi
Linux free Command Display Free and used Memory in the System
================================================================================
System administrator must maintain the health of their server. One of the critical component is memory. When server memory is full utilized, it can slow down the server performance. To monitor memory utilization, Linux have another command that called free.
### What is free command ###
**Free** command is a tool that can display amount of free and used memory in the system. The output of free command is similar with top command. Most of Linux distribution already have free command.
### How to run it ###
To run it, just type **free** on your console. Running it without an option will show you a default view with kilobyte units.
$ free
![Free default view](http://linoxide.com/wp-content/uploads/2013/12/free_default.png)
From the above screenshot we can read :
#### Memory (in kilobytes units) ####
- Total : 1026740
- Used : 843396
- Free : 183344
- Shared : 0
- Buffers : 52704
- Cached : 376384
#### Swap (in kilobytes units) ####
- Total : 1045500
- Used : 3376
- Free : 1042124
When you see the buffers/cache free memory is low or you see that the swap free is low, then a memory upgrade is needed. This mean that memory utilization is high. Please notice that the **shared memory column should be ignored** because it is obsolete.
### Display memory information in another units ###
As we mentioned before, by default free will show information in kilobytes unit. Free also provide us **-b (bytes), -k (kilobytes), -m (megabytes), -g (gigabytes) and tera (terabytes)**. To show the information in the unit we want, just pick one of them and put the option behind free command. Heres a sample output in megabytes unit.
$ free -m
![Free with megabytes unit](http://linoxide.com/wp-content/uploads/2013/12/free_m.png)
This trick is also applied to **-b, -k, -g** and **tera** option.
### Display memory information in human readable ###
Free also provide us with **-h** option which mean human readable. So what is the difference with previous option, such as **-m** (megabytes) option? The most visible difference is that **-h** option will add human readable unit after the numbers. Lets take a look a sample of it.
$ free -h
![Human readable free](http://linoxide.com/wp-content/uploads/2013/12/free_h.png)
As we can see together, there is **G (gigabyte)** letter behind 1,0 number. When the number is not reach gigabtye, free is smart enough to know it and put the appropriate unit behind each numbers. **M** letter behind let say 929 number tell us its 969 Megabytes.
### Display free with delay ###
As one of statistic tool, the best way to capture memory utilization is using a delay. To do this, we can use **-s** option followed by N seconds that we want. We can always combine more than 1 options to make the output is fit with our needs. Let say we want to capture memory utilization every 3 seconds and human readable. So the command will be like this :
$ free -hs 3
![Free with 3 seconds delay](http://linoxide.com/wp-content/uploads/2013/12/free_hs3.png)
### Display low and high memory utilization ###
If we want to show low and high memory statistics, we can use -l option. Heres a sample.
$ free -l
![Free low-high statistics](http://linoxide.com/wp-content/uploads/2013/12/free_l.png)
### Display Linux total memory ###
When we need the information of total for every column, we can add -t option behind free command. This will add 1 more row at the bottom which display it.
$ free -t
![Free with total memory](http://linoxide.com/wp-content/uploads/2013/12/free_t.png)
### Conclusion ###
Besides [vmstat][1], Free command is another simple statistic tool for capturing memory utilization. With this you can grab a quick information about what happen in your Linux memory. Free is using /proc/meminfo as a base for showing memory utilization information. As usual, you can always type man free on your console to explore more detail about free.
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-command/linux-free-command/
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://linoxide.com/linux-command/linux-vmstat-command-tool-report-virtual-memory-statistics/

View File

@ -0,0 +1,92 @@
Linux free 命令 - 显示系统中空闲和已使用的内存
================================================================================
系统管理员必须管理他们服务器的健康。其中重要的一部分是内存。当服务器内存用满时它会减小服务器的性能。为了监视内存利用率Linux有一个工具称为free。
### free是什么 ###
**free** 命令是一个显示系统中空闲和已用内存大小的工具。free命令的输出和top命令相似。大多数Linux发行版已经含有free命令。
### How to run it ###
为了运行,只要在控制台输入**free**。不带选项运行会显示一个以KB为单位的默认输出。
$ free
![free默认视图](http://linoxide.com/wp-content/uploads/2013/12/free_default.png)
从上面的截图我们看到:
#### 内存 (以KB计) ####
- Total : 1026740
- Used : 843396
- Free : 183344
- Shared : 0
- Buffers : 52704
- Cached : 376384
#### Swap (以KB计) ####
- Total : 1045500
- Used : 3376
- Free : 1042124
当你看见buffer/cache的空闲空间低或者swap的空闲空间低那么内存需要升级了。这意味这内存利用率很高。请注意 **共享内存那个应该被忽略**,因为他已经被废弃了。
### 以其他单元显示内存信息 ###
如我们先前提到的默认上free会以KB为单位显示信息。free同样提供给我们 **b (B), -k (KB), -m (MB), -g (GB) and tera (TB)**这些单位。要显示我们想要的单位只要选择一个并在free后面跟上。下面一个是以MB为单位的输出。
$ free -m
![free命令以MB为单位](http://linoxide.com/wp-content/uploads/2013/12/free_m.png)
这个技巧技巧同样适用于**-b, -k, -g** and **tera** 选项。
### 以人类可读方式显示内存信息 ###
free同样提供了**-h**选项,这意味着人类可读(译注:系统上可能并不存在-h选项已被-m取代)。那么这与其他的选项有什么不同呢,如**-m**(MB)选项? 最大的可见的不同是**-h**选项会在数字后面加上人类可读的单元。让我们看一个例子。
$ free -h
![人类可读的free](http://linoxide.com/wp-content/uploads/2013/12/free_h.png)
如我们一起看到的在1,0数字后这里是**G(GB)**字母。当数字并没有达到GB时free足够聪明来知道并在每个数字后面跟上合适的单元。后面的**M** - 数字929告诉我们它有929MB(译注: 原文为929 number tell us its 969 Megabytes这里应该为typo)。
### 延迟显示free ###
作为一个显示工具,最好的捕捉内存利用率的方法是使用延迟。为了这么做,我们可以使用**-s**选项后面跟上我们想要的N秒。我们总是在后面跟上多于1个的选项来使输出满足我们的需求。假如我们想要每3s捕捉内存利用率并且是人类可读的。那么就像这样做:
$ free -hs 3
![延迟3s显示free](http://linoxide.com/wp-content/uploads/2013/12/free_hs3.png)
### 显示高低内存利用率 ###
如果我们想要知道高低内存统计,我们可以使用-l选项。下面是一个例子。
$ free -l
![Free 的 低-高 统计](http://linoxide.com/wp-content/uploads/2013/12/free_l.png)
### 显示Linux全部内存 ###
如果我们需要每列的总计信息我们可以在free命令后面跟上-t选项。这会字底部额外加入一行显示。
$ free -t
![free命令带总计内存](http://linoxide.com/wp-content/uploads/2013/12/free_t.png)
### 总结 ###
除了[vmstat][1]以外free命令是另外一个用于捕捉内存利用率的简单统计工具。用这个你可以抓取一个快速的关于你Linux内存的信息。free命令使用/proc/meminfo作为基准来显示内存利用率信息。如往常一样你可以在控制台下输入"man free"来发现关于free的更多细节。
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-command/linux-free-command/
译者:[geekpi](https://github.com/geekpi) 校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://linoxide.com/linux-command/linux-vmstat-command-tool-report-virtual-memory-statistics/