TranslateProject/published/201401/Linux free Command - Display Free and used Memory in the System.md
wxy 1ee2fc7cbe renamed: 10 Lesser Known Useful Linux Commands- Part V.md -> 201401/10 Lesser Known Useful Linux Commands- Part V.md
renamed:    10 Useful Chaining Operators in Linux with Practical Examples.md -> 201401/10 Useful Chaining Operators in Linux with Practical Examples.md
	renamed:    10 basic examples of linux netstat command.md -> 201401/10 basic examples of linux netstat command.md
	renamed:    12 Advanced Commands For Linux Server Admins!.md -> 201401/12 Advanced Commands For Linux Server Admins!.md
	renamed:    14 New Linux Distros That Were Introduced In 2013.md -> 201401/14 New Linux Distros That Were Introduced In 2013.md
	renamed:    15 Basic MySQL Interview Questions for Database Administrators.md -> 201401/15 Basic MySQL Interview Questions for Database Administrators.md
	renamed:    "2013\357\274\232The Golden Year for Linux \342\200\223 10 Biggest Linux Achievements.md" -> "201401/2013\357\274\232The Golden Year for Linux \342\200\223 10 Biggest Linux Achievements.md"
	renamed:    2014--The year of the Linux car.md -> 201401/2014--The year of the Linux car.md
	renamed:    5 Things To Love And Hate About Ubuntu 13.10.md -> 201401/5 Things To Love And Hate About Ubuntu 13.10.md
	renamed:    8 Interesting Linux Tips And Tricks!.md -> 201401/8 Interesting Linux Tips And Tricks!.md
	renamed:    CentOS 6.5 desktop installation guide with screenshots.md -> 201401/CentOS 6.5 desktop installation guide with screenshots.md
	renamed:    "Command Line Basics \342\200\223 watch.md" -> "201401/Command Line Basics \342\200\223 watch.md"
	renamed:    Configure Your Browser To Use Tor On Ubuntu or Debian or Linux Mint.md -> 201401/Configure Your Browser To Use Tor On Ubuntu or Debian or Linux Mint.md
	renamed:    Daily Ubuntu Tips - Mount Partitions In Ubuntu From Your Desktop GUI.md -> 201401/Daily Ubuntu Tips - Mount Partitions In Ubuntu From Your Desktop GUI.md
	renamed:    "Daily Ubuntu Tips \342\200\223 Do Nothing When Laptop Lid Is Closed.md" -> "201401/Daily Ubuntu Tips \342\200\223 Do Nothing When Laptop Lid Is Closed.md"
	renamed:    "Daily Ubuntu Tips \342\200\224 Install VMware Workstation In Ubuntu.md" -> "201401/Daily Ubuntu Tips \342\200\224 Install VMware Workstation In Ubuntu.md"
	renamed:    "Daily Ubuntu Tips \342\200\224 Windows Disk Management Equivalent In Ubuntu.md" -> "201401/Daily Ubuntu Tips \342\200\224 Windows Disk Management Equivalent In Ubuntu.md"
	renamed:    "Gnu--toward the post-scarcity world \342\200\223 the Free Software Column.md" -> "201401/Gnu--toward the post-scarcity world \342\200\223 the Free Software Column.md"
	renamed:    How to Dual Boot Ubuntu and Windows Properly.md -> 201401/How to Dual Boot Ubuntu and Windows Properly.md
	renamed:    "How to Install and Configure UFW \342\200\223 An Un-complicated FireWall in Debian or Ubuntu.md" -> "201401/How to Install and Configure UFW \342\200\223 An Un-complicated FireWall in Debian or Ubuntu.md"
	renamed:    How to Upgrade to GNOME 3.10 in Ubuntu 13.10.md -> 201401/How to Upgrade to GNOME 3.10 in Ubuntu 13.10.md
	renamed:    How to install and configure Nagios on Linux.md -> 201401/How to install and configure Nagios on Linux.md
	renamed:    How to set password policy on Linux.md -> 201401/How to set password policy on Linux.md
	renamed:    How to stitch photos together on Linux.md -> 201401/How to stitch photos together on Linux.md
	renamed:    How to upgrade MySQL server on Debian or Ubuntu.md -> 201401/How to upgrade MySQL server on Debian or Ubuntu.md
	renamed:    Juju ice-cream icon design.md -> 201401/Juju ice-cream icon design.md
	renamed:    Linus Torvalds Releases Last Linux Kernel 3.13 RC for 2013.md -> 201401/Linus Torvalds Releases Last Linux Kernel 3.13 RC for 2013.md
	renamed:    Linus Torvalds Says All Contributor License Agreements Are Broken.md -> 201401/Linus Torvalds Says All Contributor License Agreements Are Broken.md
	renamed:    Linux free Command - Display Free and used Memory in the System.md -> 201401/Linux free Command - Display Free and used Memory in the System.md
	renamed:    Linux id Command - Print user ID and group ID information.md -> 201401/Linux id Command - Print user ID and group ID information.md
	renamed:    Linux is Everywhere. We show you exactly where.md -> 201401/Linux is Everywhere. We show you exactly where.md
	renamed:    Linux lsusb Command to Print information about USB on System.md -> 201401/Linux lsusb Command to Print information about USB on System.md
	renamed:    Linux vmstat Command - Tool to Report Virtual Memory Statistics.md -> 201401/Linux vmstat Command - Tool to Report Virtual Memory Statistics.md
	renamed:    "Linux who command \342\200\223 Displays who is on the system.md" -> "201401/Linux who command \342\200\223 Displays who is on the system.md"
	renamed:    "Move Dropbox\342\200\231s Folder To An External Drive In Ubuntu.md" -> "201401/Move Dropbox\342\200\231s Folder To An External Drive In Ubuntu.md"
	renamed:    New Ubuntu 14.04 Icons Are Drop-Dead Gorgeous, Might Not Arrive in Desktop Version.md -> 201401/New Ubuntu 14.04 Icons Are Drop-Dead Gorgeous, Might Not Arrive in Desktop Version.md
	renamed:    Our Top 10 Linux Applications of 2013.md -> 201401/Our Top 10 Linux Applications of 2013.md
	renamed:    Setup your personal Cloud server in minutes using ownCloud On RHEL, CentOS, Scientific Linux 6.5.md -> 201401/Setup your personal Cloud server in minutes using ownCloud On RHEL, CentOS, Scientific Linux 6.5.md
	renamed:    Software May Be Eating The World, But Open Source Software Is Eating Itself.md -> 201401/Software May Be Eating The World, But Open Source Software Is Eating Itself.md
	renamed:    The Debian Administrator's Handbook updated for Debian 7 Wheezy published and freely available for download.md -> 201401/The Debian Administrator's Handbook updated for Debian 7 Wheezy published and freely available for download.md
	renamed:    The Fedora Project Will No Longer Name Its Linux Distributions.md -> 201401/The Fedora Project Will No Longer Name Its Linux Distributions.md
	renamed:    The Genius Of Linux Is Community, Not Technology.md -> 201401/The Genius Of Linux Is Community, Not Technology.md
	renamed:    Top 10 Linux Distros For Hackers!.md -> 201401/Top 10 Linux Distros For Hackers!.md
	renamed:    Tunnel SSH Connections Over SSL Using 'Stunnel' On Debian 7  Ubuntu 13.10.md -> 201401/Tunnel SSH Connections Over SSL Using 'Stunnel' On Debian 7  Ubuntu 13.10.md
	renamed:    Ubuntu Stores Your Wi-Fi Passwords By Default!.md -> 201401/Ubuntu Stores Your Wi-Fi Passwords By Default!.md
	renamed:    Ubuntu Will Reach True Convergence Before Microsoft, Says Shuttleworth.md -> 201401/Ubuntu Will Reach True Convergence Before Microsoft, Says Shuttleworth.md
	renamed:    Understanding Linux cd Command with Examples.md -> 201401/Understanding Linux cd Command with Examples.md
	renamed:    look--Linux Command To Verify Spellings And Display Lines Beginning With A String.md -> 201401/look--Linux Command To Verify Spellings And Display Lines Beginning With A String.md
2014-02-03 20:55:51 +08:00

101 lines
4.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Linux free 命令 - 显示系统中空闲和已使用的内存
================================================================================
系统管理员必须维护他们服务器的健康运行。其中一个重要的部分就是内存。当服务器内存使用率过高时它会降低服务器的性能。Linux有一个称为 **free** 的工具,来监控内存使用率。
### free 命令是什么 ###
**free** 命令是一个显示系统中空闲和已用内存大小的工具。free 命令的输出和 top 命令相似。大多数Linux发行版已经含有 free 命令。
### 如何运行 free ###
想要运行,只需在控制台输入**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
译注关于Buffers和Cached的区别来自 http://www.taobaotesting.com/blogs/qa?bid=2265 的一段解释如下:
> buffers是指用来给块设备做的缓冲大小他只记录文件系统的metadata以及 tracking in-flight pages.
> cached是用来给文件做缓冲。
> 那就是说buffers是用来存储目录里面有什么内容权限等等。而cached直接用来记忆我们打开的文件
#### Swap (以KB计) ####
- Total全部 : 1045500
- Used已用 : 3376
- Free可用 : 1042124
当你看见 buffer/cache 的空闲空间低或者 swap 的空闲空间低,说明内存需要升级了。这意味这内存利用率很高。请注意 **shared共享内存列应该被忽略** ,因为它已经被废弃了。
### 以其它单元显示内存信息 ###
如我们先前提到的,默认 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** 以及 **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这里应该为输入错误)。
### 间隔显示 free ###
作为一个状态检查工具,最好的统计内存利用率的方法是使用延迟间隔。这么做的话,我们可以使用**-s**选项后面跟上我们想要间隔的N秒数。我们可以在后面合并几个选项来使输出满足我们的需求。假如我们想要每3秒统计一次内存利用率并且适于人类可读那么就像这样做:
$ 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) 校对:[Caroline](https://github.com/carolinewuyan)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://linoxide.com/linux-command/linux-vmstat-command-tool-report-virtual-memory-statistics/