Linux Commands – free
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed df command in Linux which is used to get file system disk space usage.
https://cloudaffaire.com/linux-commands-df/
In this blog post, we will discuss free command in Linux. free command is used to display current system memory usage. By default, free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo. The displayed columns are:
- total: Total installed memory (MemTotal and SwapTotal in /proc/meminfo)
- used: Used memory (calculated as total – free – buffers – cache)
- free: Unused memory (MemFree and SwapFree in /proc/meminfo)
- shared: Memory used (mostly) by tmpfs (Shmem in /proc/meminfo, displayed as zero if not available)
- buffers: Memory used by kernel buffers (Buffers in /proc/meminfo)
- cache: Memory used by the page cache and slabs (Cached and SReclaimable in /proc/meminfo)
- buff/cache: Sum of buffers and cache
- available: Estimation of how much memory is available for starting new applications, without swapping.
Linux Commands – free:
You can use free command to get current memory and swap utilization. By default, memory usage is printed in units of 1024 bytes (kibibytes), but this can be overridden with different options.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
########################### ## Linux Commands | free ## ########################### ## Prerequisites: One Unix/Linux/POSIX-compliant operating system with bash shell ##----- ## free ##----- ## free [options] ## free command free ## displays physical and swap memory usage of the system ## total used free shared buff/cache available ## Mem: 1006960 87264 431352 440 488344 752956 ## Swap: 0 0 0 cat /proc/meminfo ## you can find much more details in /proc/meminfo file |
You can use free -h or –human options to show all output fields automatically scaled to the shortest three digit unit and display the units of print out. The following units are used.
- B = bytes
- Ki = kibibyte (1024 bytes)
- Mi = mebibyte (1024 kibibyte)
- Gi = gibibyte (1024 mebibyte)
- Ti = tebibyte (1024 gibibyte)
- Pi = pebibyte (1024 tebibyte)
1 2 3 4 |
free -h ## display the size in human redable format ## total used free shared buff/cache available ## Mem: 983M 85M 420M 496K 477M 734M ## Swap: 0B 0B 0B |
You can use free -w or –wide options to switch to the wide mode which produces lines longer than 80 characters. In wide mode buffers and cache are reported in two separate columns.
1 2 3 4 5 6 7 |
## free -w or --wide options free -w ## displays lines longer than 80 characters. ## buffers and cache are reported in two separate columns ## total used free shared buffers cache available ## Mem: 1006960 87400 430824 496 0 488736 752764 ## Swap: 0 0 0 |
You can use free -l or –lohi options to show detailed low and high memory statistics.
1 2 3 4 5 6 7 8 |
## free -l or --lohi options free -l ## displays detailed low and high memory statistics ## total used free shared buff/cache available ## Mem: 1006960 89464 426732 496 490764 750684 ## Low: 1006960 580228 426732 ## High: 0 0 0 ## Swap: 0 0 0 |
You can use free -t or –total options to display a line showing the column totals.
1 2 3 4 5 6 7 |
## free -t or --total options free -t ## displays a line showing the column totals ## total used free shared buff/cache available ## Mem: 1006960 89488 426700 496 490772 750660 ## Swap: 0 0 0 ## Total: 1006960 89488 426700 |
You can use free -s or –seconds delay options to continuously display the result delay seconds apart. You may actually specify any floating-point number for delay using either . or , for the decimal point. You can use -c or –count options with -s delay option to display the result count times every delay seconds.
1 2 3 4 5 6 |
## free -s or --seconds delay options ## free -c or --count count options free -s 1 ## displays memory usage every one seconds free -s 1 -c 5 ## displays memory usage every one seconds for five times |
free command provides lots of options to control the size units in the output. Below is the list of all available size options in free command.
- -b, –bytes: Display the amount of memory in byt
- –kibi: Display the amount of memory in kibibytes. (default)
- –mebi: Display the amount of memory in mebibyt
- –gibi: Display the amount of memory in gibibyt
- –tebi: Display the amount of memory in tebibyt
- –pebi: Display the amount of memory in pebibytes.
- –si: Display in power of 1000 instead power of 1024
- –kilo: Display the amount of memory in kilobytes. Implies –si
- –mega: Display the amount of memory in megabytes. Implies –si
- –giga: Display the amount of memory in gigabytes. Implies –si
- –tera: Display the amount of memory in terabytes. Implies –si
- –peta: Display the amount of memory in petabytes. Implies –si
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
## free size options free --bytes ## Display the amount of memory in byt free --kibi ## Display the amount of memory in kibibytes. (default) free --mebi ## Display the amount of memory in mebibyt free --gibi ## Display the amount of memory in gibibyt free --tebi ## Display the amount of memory in tebibyt free --pebi ## Display the amount of memory in pebibytes. free --si ## Display in power of 1000 instead power of 1024 free --kilo ## Display the amount of memory in kilobytes. Implies --si free --mega ## Display the amount of memory in megabytes. Implies --si free --giga ## Display the amount of memory in gigabytes. Implies --si free --tera ## Display the amount of memory in terabytes. Implies --si free --peta ## Display the amount of memory in petabytes. Implies --si |
Hope you have enjoyed this article. In the next blog post, we will discuss crontab command in Linux.