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
4.9 KiB
Linux free 命令 - 显示系统中空闲和已使用的内存
系统管理员必须维护他们服务器的健康运行。其中一个重要的部分就是内存。当服务器内存使用率过高时,它会降低服务器的性能。Linux有一个称为 free 的工具,来监控内存使用率。
free 命令是什么
free 命令是一个显示系统中空闲和已用内存大小的工具。free 命令的输出和 top 命令相似。大多数Linux发行版已经含有 free 命令。
如何运行 free
想要运行,只需在控制台输入free 即可。不带选项运行会显示一个以KB为单位的默认输出。
$ free
从上面的截图我们看到:
内存 (以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
这个技巧同样适用于**-b, -k, -g** 以及 –tera 选项。
以适于人类可读方式显示内存信息
free 同样提供了**-h选项,这意味着适于人类可读(译注:系统上可能并不存在-h选项,已被-m取代)。那么这与其它的选项有什么不同呢,如-m**(MB)选项? 可见的最大不同是**-h**选项会在数字后面加上适于人类可读的单位。让我们看一个例子。
$ free -h
如我们一起看到的,在1,0数字后这里是G(GB)字母。当数字并没有达到GB时,free足够聪明来知道并在每个数字后面跟上合适的单位。后面的M - 数字929告诉我们它有929MB(译注: 原文为929 number tell us its 969 Megabytes,这里应该为输入错误)。
间隔显示 free
作为一个状态检查工具,最好的统计内存利用率的方法是使用延迟间隔。这么做的话,我们可以使用**-s**选项后面跟上我们想要间隔的N秒数。我们可以在后面合并几个选项来使输出满足我们的需求。假如我们想要每3秒统计一次内存利用率并且适于人类可读,那么就像这样做:
$ free -hs 3
显示高低内存利用率
如果我们想要知道高低内存统计,我们可以使用-l选项。下面是一个例子。
$ free -l
显示 Linux 全部内存
如果我们需要每列的总计信息,我们可以在 free 命令后面跟上 -t 选项。这会在字底部额外加入一行显示。
$ free -t
总结
除了vmstat以外,free 命令也是一个用于统计内存利用率的简单统计工具。用这个你可以快速查看你的 Linux 内存信息。free 命令使用 /proc/meminfo 作为基准来显示内存利用率信息。如往常一样,你可以在控制台下输入 man free 来获取更多关于 free 的信息。