How to Check Memory Usage on Linux: Simple Commands
To check memory usage on Linux, use the
free command to see total, used, and available memory. You can also use top or vmstat for real-time memory stats and detailed system info.Syntax
The basic commands to check memory usage are:
free -h: Shows memory usage in human-readable format.top: Displays real-time system processes and memory usage.vmstat 1 5: Shows memory and system stats every second for 5 times.
bash
free -h top vmstat 1 5
Example
This example uses free -h to display memory usage in a clear, readable way. It shows total, used, free, shared, buff/cache, and available memory.
bash
free -h
Output
total used free shared buff/cache available
Mem: 7.7Gi 2.1Gi 3.2Gi 150Mi 2.4Gi 5.0Gi
Swap: 2.0Gi 0B 2.0Gi
Common Pitfalls
Many users mistake used memory as the only important value, but Linux uses free memory for cache and buffers to speed up the system. The available memory is a better indicator of how much memory is free for new applications.
Also, running top without understanding its columns can confuse beginners. Focus on the RES (resident memory) column for actual memory used by processes.
bash
free # Wrong: Assuming 'used' means memory is low # Right: Check 'available' for free memory
Quick Reference
| Command | Description |
|---|---|
| free -h | Show memory usage in human-readable format |
| top | Display real-time processes and memory usage |
| vmstat 1 5 | Show memory and system stats every second for 5 times |
| cat /proc/meminfo | Detailed memory info from system file |
Key Takeaways
Use
free -h for a quick, clear memory usage summary.Check the
available memory, not just used, to understand free memory.Use
top for real-time memory and process monitoring.Avoid confusing cache/buffer memory with used memory.
Use
vmstat for detailed periodic memory stats.