在Linux系統中,我們查看、監控系統記憶體使用情況,一般最常用的命令就是free。free命令其實非常簡單,參數也非常簡單,但是裡面很多知識點未必你都掌握了。下麵總結一下我所瞭解的free命令。如有不足,敬請指出。文章很多知識點參考了下麵參考資料,都是在這些前輩文章的基礎上所做的一個驗證和總結。 f...
在Linux系統中,我們查看、監控系統記憶體使用情況,一般最常用的命令就是free。free命令其實非常簡單,參數也非常簡單,但是裡面很多知識點未必你都掌握了。下麵總結一下我所瞭解的free命令。如有不足,敬請指出。文章很多知識點參考了下麵參考資料,都是在這些前輩文章的基礎上所做的一個驗證和總結。
free命令介紹
free命令是一個顯示系統中空閑和已用記憶體大小的工具。大多數Linux發行版都包含有free命令,但是版本可能不一樣。free 命令使用/proc/meminfo中的值作為基準來顯示記憶體利用率信息。free命令的英文介紹:free - displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. The shared memory column represents the ’Shmem’ value. The available memory column represents the ’MemAvailable’ value.
free參數介紹
你可以在控制臺下輸入man free命令查看更多關於free命令的信息。另外你可以使用下麵命令獲取free的使用信息(雖然是一個無效參數)
[root@localhost ~]# free --help
free: invalid option -- '-'
usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V]
-b,-k,-m,-g show output in bytes, KB, MB, or GB
-l show detailed low and high memory statistics
-o use old format (no -/+buffers/cache line)
-t display total for RAM + swap
-s update every [delay] seconds
-c update [count] times
-a show available memory if exported by kernel (>80 characters per line)
-V display version information and exit
free命令的參數有下麵一些,不同版本可能有所區別(procps version 3.2.8):
參數 |
功能 |
-b -k -m -g |
分別以Byte、KB、MB、GB為單位顯示記憶體的使用情況 |
-l |
show detailed low and high memory statistics |
-o |
使用舊的格式顯示記憶體的使用信息,沒有描述 -/+buffers/cache信息這一行。 |
-t |
顯示記憶體總和列 |
-s |
<間隔秒數> 持續觀察記憶體使用狀況。 |
-c |
結合參數-s使用,表示更新多少次。update [count] times |
-a |
show available memory if exported by kernel (>80 characters per line) |
-V |
顯示free命令版本信息並退出該命令 |
例子:
1:以MB為單位顯示記憶體的使用情況
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 11912 957 10955 1 167 498
-/+ buffers/cache: 291 11620
Swap: 12287 0 12287
[root@localhost ~]#
2:每隔3秒顯示記憶體的使用信息
[root@localhost ~]# free -m -s 3
total used free shared buffers cached
Mem: 11912 957 10955 1 167 498
-/+ buffers/cache: 292 11620
Swap: 12287 0 12287
total used free shared buffers cached
Mem: 11912 957 10955 1 167 498
-/+ buffers/cache: 292 11620
Swap: 12287 0 12287
total used free shared buffers cached
Mem: 11912 957 10955 1 167 498
-/+ buffers/cache: 292 11620
Swap: 12287 0 12287
total used free shared buffers cached
Mem: 11912 957 10955 1 167 498
-/+ buffers/cache: 292 11620
Swap: 12287 0 12287
3:顯示記憶體總和列
[root@localhost ~]# free -mt
total used free shared buffers cached
Mem: 11912 957 10955 1 167 498
-/+ buffers/cache: 292 11620
Swap: 12287 0 12287
Total: 24200 957 23243
[root@localhost ~]#
4:顯示高低記憶體利用率
[root@localhost ~]# free -ml
total used free shared buffers cached
Mem: 11912 957 10955 1 167 498
Low: 11912 957 10955
High: 0 0 0
-/+ buffers/cache: 292 11620
Swap: 12287 0 12287
[root@localhost ~]#
5:每2秒顯示一次記憶體使用情況,一共顯示3次
[root@localhost ~]# free -s 2 -c 3
total used free shared buffers cached
Mem: 12198496 981976 11216520 1176 171260 510160
-/+ buffers/cache: 300556 11897940
Swap: 12582908 0 12582908
total used free shared buffers cached
Mem: 12198496 981976 11216520 1176 171260 510160
-/+ buffers/cache: 300556 11897940
Swap: 12582908 0 12582908
total used free shared buffers cached
Mem: 12198496 981976 11216520 1176 171260 510160
-/+ buffers/cache: 300556 11897940
Swap: 12582908 0 12582908