0
0
Linux-cliHow-ToBeginner · 3 min read

How to Use Free Command in Linux: Memory Usage Explained

Use the free command in Linux to display the system's memory usage including total, used, free, shared, buffer/cache, and available memory. Run free -h for human-readable output with sizes in MB or GB.
📐

Syntax

The basic syntax of the free command is:

  • free [options] - Runs the command with optional flags.
  • -h - Shows memory sizes in human-readable format (e.g., MB, GB).
  • -m - Displays memory in megabytes.
  • -g - Displays memory in gigabytes.
  • -s N - Continuously updates memory info every N seconds.
bash
free [options]
💻

Example

This example shows how to use free -h to see memory usage in a readable format:

bash
free -h
Output
total used free shared buff/cache available Mem: 7.7G 2.1G 3.2G 150M 2.4G 5.0G Swap: 2.0G 0B 2.0G
⚠️

Common Pitfalls

Common mistakes when using free include:

  • Confusing free memory with available memory. Available memory includes cached and buffered memory that can be freed.
  • Not using -h for human-readable output, which makes numbers hard to read.
  • Ignoring swap usage which can indicate memory pressure.
bash
free

# Better way:
free -h
📊

Quick Reference

OptionDescription
-hShow sizes in human-readable format (MB, GB)
-mShow sizes in megabytes
-gShow sizes in gigabytes
-s NRepeat output every N seconds
-tDisplay total memory (RAM + swap)

Key Takeaways

Use free -h to get easy-to-read memory usage in Linux.
Remember that 'available' memory includes cached data that can be freed if needed.
Check swap usage to understand if your system is running low on RAM.
Use options like -s to monitor memory continuously.
Avoid confusing free memory with available memory for accurate system health.