Home > Environment & Utility > free

free Command Guide: Check System Memory Usage

The `free` command is used on Linux systems to display the total amount of available physical memory (RAM) and swap memory, along with their usage and free space. It is an essential tool for system performance monitoring and troubleshooting. Through this guide, learn how to easily check memory information using various options of the `free` command.

free Overview

The `free` command provides a snapshot of how the operating system is currently managing memory. This helps determine whether the system is experiencing performance degradation due to memory shortage or has sufficient free memory.

Understanding Memory Types

To correctly interpret the output of the `free` command, it is important to understand the concepts of physical memory (RAM), swap memory, and buffer/cache.

Key Memory Items

  • Mem (Physical Memory): The total amount of RAM installed in the system. This is the actual memory space used by the operating system and running programs.
  • Swap (Swap Memory): Space on the hard disk used when physical memory is low. It is used like RAM but is much slower.
  • total: The total memory or swap space.
  • used: The currently used memory or swap space.
  • free: The available memory or swap space.
  • shared: Memory shared by multiple processes.
  • buff/cache: Memory used for kernel buffers and page cache. This is not 'wasted' memory but is rather 'available' memory that can be allocated to applications whenever needed.
  • available: The amount of memory that can be allocated to new applications upon request. It provides a more accurate representation of 'available' memory than the `free` field. (Provided in Linux kernel 3.14 and later)

Key free Command Options

The `free` command allows you to change output units or filter specific information through various options.

1. Output Unit Options

2. Other Useful Options

Generated command:

Try combining the commands.

Description:

`free` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Through various usage examples of the `free` command, learn how to effectively monitor and analyze system memory usage.

Output Memory Information in a Human-Readable Format

free -h

The most common option, which automatically converts memory information to MB or GB units for easy viewing.

Output Memory Information in Megabytes

free -m

Use this when you want to clearly check memory usage in megabytes (MB).

Update Memory Information 3 times at 5-second Intervals

free -h -s 5 -c 3

Useful for observing system memory changes over a short period. (e.g., observing memory usage changes while running a specific program)

Separate Buffer and Cache Output (in MB)

free -m -w

Use this when you want to see buffer and cache memory as independent columns. The `-w` option is primarily used for debugging or detailed analysis.

Log Memory Usage with Unix Timestamp (Script Example)

echo "$(date +%s),$(free -m | grep Mem | awk '{print $2,$3,$4,$6,$7}')" >> mem_log.csv

Can be utilized in shell scripts to periodically log memory usage and create time-series data.


Same category commands