Linux free command
The free
command in Linux is used to display the amount of free and used memory in the system, including physical RAM and swap space. It provides a snapshot of the memory usage on your system and is commonly used for quick checks on system resources.
Basic Syntax:
Commonly Used Options:
-h
: Human-readable format (displays memory in KB, MB, or GB).-m
: Display memory in megabytes (MB).-g
: Display memory in gigabytes (GB).-t
: Show the total memory (including physical and swap memory).
Basic Usage:
Sample Output:
Output Explanation:
Mem:
- The physical RAM (Random Access Memory) usage.- total: Total amount of RAM in the system (e.g., 8.0Gi).
- used: RAM currently used by processes (e.g., 1.7Gi).
- free: RAM that is completely free and unallocated (e.g., 3.8Gi).
- shared: Memory used by the tmpfs (temporary filesystem) or shared memory (e.g., 234Mi).
- buff/cache: Memory used by the kernel buffers and cache (e.g., 2.4Gi).
- available: An estimate of how much memory is available for starting new applications without swapping (e.g., 5.6Gi).
Swap:
- The swap space usage.- total: The total swap space available (e.g., 2.0Gi).
- used: The amount of swap space currently in use (e.g., 0B).
- free: The remaining swap space that is not used (e.g., 2.0Gi).
Example with -h
option (human-readable format):
Sample Output:
- The output shows memory in human-readable format (e.g., Gi for gibibytes and Mi for mebibytes).
Example with -m
option (display in megabytes):
Sample Output:
- Here, memory is displayed in megabytes (MB).
Explanation of Columns:
total
: The total amount of memory (RAM or swap) available on your system.used
: The amount of memory that is currently in use by running processes.free
: The amount of memory that is completely unused and available for allocation.shared
: The amount of memory used by shared resources like tmpfs.buff/cache
: The memory used by the operating system for buffers and cached data (this memory can be released if needed).available
: The amount of memory that is readily available for new applications without needing to swap.
Swap Memory:
Swap is space on your hard drive used when RAM is full. The system moves inactive pages from RAM to swap to free up memory for active processes. The swap usage can indicate whether your system is running out of RAM and starting to rely on swap, which is slower.
Example with -t
option (total memory):
Sample Output:
Total:
: This line includes both physical memory (RAM) and swap space combined.
Summary of Columns in free
:
- Mem:
total
: Total system memory.used
: Memory currently in use by processes.free
: Memory that is not being used.shared
: Memory being used for shared resources (like tmpfs).buff/cache
: Memory used by the kernel buffers and cache.available
: Memory that is available for use by new processes (taking cache into account).
- Swap:
total
: Total swap space.used
: Amount of swap space in use.free
: Amount of unused swap space.
Conclusion:
The free
command is a simple yet essential tool for checking the memory and swap usage on a Linux system. It gives you an immediate sense of the overall memory usage and helps identify potential memory bottlenecks, especially when combined with other system monitoring tools. The -h
, -m
, -t
, and other options allow you to customize the output for better readability and precision.