free's Examples

free Command:free is the most commonly used command for checking the memory usage of a Linux system. It displays information about the total, used, and free memory.

free -h

top Command

top

The simplest way to check the RAM memory usage is to display the contents of the /proc/meminfo virtual file. This file is used by the freetopps , and other system information commands.

cat /proc/meminfo

ps_mem Script

sudo pip3 install ps_mem

output in bytes

-b

output in kibibytes

-k

output in mebibytes

-m

 Display System Memory

free

 Display Memory in Gigabytes

free -g

Display Total Line

free -t

Display Memory Status for Regular Intervals

free -s

Show Low and High Memory Statistics

free -l

Check Free Version

free -V

Showing the Column Totals

free -h -t

Showing Memory Usage in Other Metrics

free --mega

by using -h option shows the output in human readable format

free -h

by using free command we see the results for total, used and free memory on system by accessing the system kernel. it also displays the shared cache and available 

$ free

it will show us onnly one output and this output will be changing at regular intervals

watch free -h

-s option is used to instriuts free command to refresh the puput for every 3 sec. to stop th process ctrl+c

free -s3

gives the output in mebibytes

free -m

use the si the power 1024 and in megabytes

free --si -m

-c option instructs the free command to automatocally quit after refreshing 4 times

free -c 4

to see the buffer and cache colums seperatly

free -w

total option instructs free to show the toatal memory of used,free total columns of memory and swap columns

free -h --total

the command produces ouput in mebibytes with 3 seconds delay and quits after refreshing the ouput for 4 times

free -m -s3 -c4

Output Example:

              total        used        free      shared  buff/cache   available
Mem:        16000000     8000000     4000000      500000     4000000    10000000
Swap:        8000000      2000000     6000000

Explanation:

  • Mem: Displays total, used, free, shared, cache, and available memory.
  • Swap: Shows swap memory details.

free

Output Example:

              total        used        free      shared  buff/cache   available
Mem:           16G         8G         4G       500M        4G         10G
Swap:           8G         2G         6G
 

Explanation:
The -h flag makes it human-readable (e.g., GB, MB, KB).

free -h

Displays memory in MB (Megabytes).

free -m

Displays memory in GB (Gigabytes).

free -g

This updates the memory usage every 2 seconds. (Press Ctrl+C to stop.)

free -h -s 2

Output Example:

              total        used        free      shared  buff/cache   available
Mem:           16G         8G         4G       500M        4G         10G
Swap:           8G         2G         6G
Total:        24G        10G        10G
 

Explanation:
The -t flag adds a "Total" row summing up RAM and swap memory.

free -h -t

This hides swap memory details and only shows physical RAM usage.

free -h --no-swap

MemTotal:       16000000 kB
MemFree:         4000000 kB
MemAvailable:   10000000 kB
SwapTotal:       8000000 kB
SwapFree:        6000000 kB
Explanation:
This provides detailed memory stats beyond what free shows.

cat /proc/meminfo

This shows memory usage before and after running a program within 10 seconds.

free -h && sleep 10 && free -h

Output Example:

Used Memory: 50.00%
 

Explanation:
This calculates the percentage of used RAM.

free | awk '/Mem:/ {printf("Used Memory: %.2f%\n", $3/$2 * 100)}'

Displays system memory usage (total, used, free).

free -h

DevOpsSchool
Typically replies within an hour

DevOpsSchool
Hi there 👋

How can I help you?
×
Chat with Us