free Command in Linux
Memory is an important system resource, especially on Linux servers running websites, databases, and applications. When troubleshooting performance issues, developers and system administrators often need to quickly check how much RAM is being used.
The free command provides a simple summary of physical memory and swap usage.
What Is the free Command?
Run the command:
free
It displays information about memory such as:
- Total memory
- Used memory
- Free memory
- Available memory
- Swap usage
For easier-to-read values, use:
free -h
The -h option displays memory values in human-readable units.
Understanding the Output
A typical free -h output may look like:
total used free shared buff/cache available
Mem: 7.7Gi 2.1Gi 1.2Gi 200Mi 4.4Gi 5.1Gi
Swap: 2.0Gi 0B 2.0Gi
The exact numbers will vary depending on the server.
Total shows the available memory.
Used shows memory currently in use.
Free shows memory that is not currently allocated.
Available provides an estimate of memory available for new applications.
Swap shows usage of configured swap space.
Useful Options
For human-readable output:
free -h
To continuously monitor memory:
free -h -s 5
This refreshes the output every five seconds.
To display the result only a specific number of times:
free -h -c 3
Why Use free?
The command is useful when:
- A server appears slow.
- An application consumes excessive RAM.
- You need to check swap usage.
- Troubleshooting memory-related problems.
- Monitoring Linux server resources.
It is also useful to combine free with commands such as top, htop, and /proc/meminfo for deeper investigation.
free vs cat /proc/meminfo
Both can provide memory information, but they serve different purposes.
free -h
provides a concise summary.
cat /proc/meminfo
provides much more detailed memory statistics.
For a quick health check, free -h is usually the easier command.
Best Practices
Do not assume that low free memory automatically means a Linux server has a problem. Linux uses available memory for useful caching, so the available value is often more informative when assessing whether applications can obtain additional memory.
Monitor memory over time and investigate consistently high usage, heavy swap activity, or application-specific memory growth.
Conclusion
The Linux free command is a simple and useful tool for checking RAM and swap usage. Using free -h makes the output easier to understand and is especially helpful during server troubleshooting.
For deeper analysis, combine it with tools such as top, htop, and /proc/meminfo to get a more complete picture of system memory usage.