How to Check Memory Usage on Raspberry Pi Quickly
To check memory usage on a Raspberry Pi, use the
free -h command to see total, used, and free memory in a human-readable format. For real-time monitoring, top or htop commands provide dynamic views of memory and CPU usage.Syntax
Here are common commands to check memory usage on Raspberry Pi:
free -h: Shows total, used, free, and available memory in human-readable form.top: Displays real-time system processes and memory usage.vmstat: Reports virtual memory statistics.
bash
free -h top vmstat 1 5
Example
This example uses free -h to display memory usage in a clear format.
bash
free -h
Output
total used free shared buff/cache available
Mem: 3.8Gi 1.2Gi 1.5Gi 100Mi 1.1Gi 2.3Gi
Swap: 100Mi 0B 100Mi
Common Pitfalls
Some common mistakes when checking memory on Raspberry Pi:
- Using
freewithout-hshows bytes, which is hard to read. - Confusing cached and buffered memory as used memory; Linux uses free memory for cache to speed up processes.
- Not running
toporhtopwith proper permissions may hide some details.
bash
free # Better way: free -h
Quick Reference
| Command | Description |
|---|---|
| free -h | Show memory usage in human-readable format |
| top | Real-time system and memory usage display |
| htop | Enhanced interactive process viewer (install first) |
| vmstat 1 5 | Show virtual memory stats every second for 5 times |
Key Takeaways
Use
free -h for a quick, readable summary of memory usage.Run
top or htop to monitor memory and CPU in real time.Remember Linux uses free memory for cache; check 'available' memory for true free space.
Add
-h to commands like free to see sizes in MB/GB instead of bytes.Install
htop with sudo apt install htop for a user-friendly interface.