一、free命令概述
Free命令用於顯示系統中空閑和已用的內存數量,包括物理內存和swap內存。
$ free
total used free shared buff/cache available
Mem: 2041216 1228532 364200 46368 450484 705208
Swap: 2097148 175680 1921468
命令輸出結果解釋:
1、total: 總物理內存大小
2、used: 已使用物理內存大小
3、free: 空閑物理內存大小
4、shared: 被共享使用的物理內存大小
5、buff/cache: 緩存的物理內存大小
6、available: 系統可用物理內存大小
二、free命令的參數
Free命令的參數如下所示:
$ free --help
Usage: free [options]
Display amount of free and used memory in the system
Options:
-b, --bytes show output in bytes
-k, --kilo show output in kilobytes
-m, --mega show output in megabytes
-g, --giga show output in gigabytes
--tera show output in terabytes
-o, --old-style old style output
-t, --total show total for RAM + swap
-s N, --seconds N repeat printing every N seconds
-c N, --count N repeat printing N times, then exit
-h, --human show human-readable output
--si use powers of 1000 not 1024
-V, --version display version information and exit
-h, --help display this help and exit
三、free命令的實踐應用
1、free命令的實時監測
Free命令可以實時監測系統內存的變化情況。在監測過程中,可以通過-c參數設置監測的次數,或者通過-s參數設置監測的時間間隔。
# 每3秒輸出一次內存使用狀態,循環10次
$ free -s 3 -c 10
2、free命令生成內存使用報表
Free命令還可以生成內存使用情況的報表。通過-c參數可以設置生成幾輪報表,通過-s參數設置生成報表的時間間隔。
# 生成5輪內存使用情況報表,每隔5秒生成一次報表
$ free -s 5 -c 5 -h
total used free shared buff/cache available
Mem: 7.7G 1.8G 4.5G 72M 1.4G 5.7G
Swap: 2.0G 0B 2.0G
total used free shared buff/cache available
Mem: 7.7G 1.8G 4.5G 72M 1.4G 5.7G
Swap: 2.0G 0B 2.0G
total used free shared buff/cache available
Mem: 7.7G 1.8G 4.5G 72M 1.4G 5.7G
Swap: 2.0G 0B 2.0G
total used free shared buff/cache available
Mem: 7.7G 1.8G 4.5G 72M 1.4G 5.7G
Swap: 2.0G 0B 2.0G
total used free shared buff/cache available
Mem: 7.7G 1.8G 4.5G 72M 1.4G 5.7G
Swap: 2.0G 0B 2.0G
3、free命令篩選特定的數據項
Free命令還可以通過選項參數來篩選特定的數據項,例如通過-b參數來顯示內存使用情況的字節數,通過-k參數來顯示內存使用情況的千字節數,通過-m參數來顯示內存使用情況的兆字節數。
# 顯示內存使用情況千字節數
$ free -k
四、總結
本文對Linux free命令進行了詳細的闡述,包括free命令的概述,命令參數的解析,以及free命令在實踐應用中的使用方法。讀者可以通過本文了解到如何使用free命令來監測內存使用情況,生成內存使用情況報表,以及如何篩選特定的數據項。通過本文的學習,相信讀者對Linux系統中的內存管理有更為深入的認識和理解。
原創文章,作者:OZUUF,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/370309.html