🧠Command: free (Check RAM/Memory Usage)
The free command provides a quick, tabular summary of your system's memory. It’s the fastest way to see how much RAM is occupied and how much is sitting idle.
1. The "Why"
When you are developing or multitasking, your system's performance depends heavily on available memory.
- Identify RAM Pressure: See if your system is starting to swap to your SSD (which is much slower than RAM).
- Monitor Cache: Understand why your RAM looks "full" even when you aren't running heavy apps (hint: it's usually just Linux being efficient with caching).
- Verify Swap: Make sure your Swap partition (virtual memory) is active and being used correctly.
2. Basic Syntax
free [OPTIONS]
Like many other tools, the default output is in kibibytes, which is difficult to read. You’ll almost always use the human-readable flag.
3. The "Must-Have" Flag: -h
Using -h gives you the output in Gigabytes (G) or Megabytes (M).
free -h
Understanding the Output Columns:
- Total: The total amount of physical RAM installed in your system.
- Used: What your applications and the system are currently using.
- Free: Memory that is completely untouched.
- Shared: Memory used by
tmpfs(RAM disks) and for inter-process communication. - Buff/Cache: Memory used by the Linux kernel to speed up disk access.
- Available: The most important number. This is how much memory is actually available for a new application to start without forcing the system to swap.
4. How Linux Manages Memory
A common point of confusion for new Linux users is seeing a very low "Free" number.
In Linux, "Free RAM is wasted RAM." The kernel uses nearly all your unused RAM as a "Cache" to store recently accessed files. This makes your system feel fast. If an application (like Android Studio) needs that memory, the kernel will instantly drop the cache and give the RAM to the app.
Rule of Thumb: Focus on the Available column, not the Free column.
5. Practical Examples
A. Checking Swap Specifically
If you want to see if your system is "swapping" (moving RAM to the disk because it's full):
free -h
Look at the Swap row. If Used is a high number, your system might feel slow.
B. Continuous Monitoring
To watch your memory usage update every few seconds (useful while starting a heavy compilation):
free -h -s 3
(This refreshes every 3 seconds. Press Ctrl + C to stop.)
C. Wide Format
To see the buffers and cache separated into two different columns:
free -wh
6. Pro-Tips
- The "OOM Killer": If you see your Available memory hit zero, the Linux "Out of Memory Killer" will start force-closing your biggest apps (usually your browser or Java IDE) to prevent the whole system from crashing.
7. Summary Reference
| Goal | Command |
|---|---|
| Quick Human-Readable Check | free -h |
| Detailed "Wide" View | free -wh |
| Continuously Update | free -h -s [seconds] |
| Display Total at Bottom | free -ht |