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
-hfor 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
| Option | Description |
|---|---|
| -h | Show sizes in human-readable format (MB, GB) |
| -m | Show sizes in megabytes |
| -g | Show sizes in gigabytes |
| -s N | Repeat output every N seconds |
| -t | Display 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.