The free command provides a snapshot of the total, used, free, shared, and available memory in a RHEL 8 system. It gathers this information from the /proc/meminfo file, offering a quick way to diagnose memory usage and potential bottlenecks. Understanding this output is a fundamental skill for any system administrator managing server performance and resource allocation.
Example 1: free
# Display memory usage in kibibytes (the default unit)
free
Explanation: This is the most basic execution of the command. It presents the memory and swap statistics in kibibytes, which provides the most granular view but can be difficult to read on systems with large amounts of RAM.
Example 2: free -h
# Show memory statistics in a human-readable format
free -h
Explanation: The -h option is the most common flag used, as it automatically scales the output to the most appropriate unit, such as megabytes (M), gigabytes (G), or terabytes (T). This makes the memory usage report instantly understandable at a glance.
Example 3: free -m
# Output all memory values in mebibytes
free -m
Explanation: Using the -m flag forces the command to display all memory values in mebibytes (1024*1024 bytes). This is useful for consistently comparing memory usage over time or across different systems when a standard unit is required for reporting.
Example 4: free -g
# Output all memory values in gibibytes
free -g
Explanation: For servers equipped with a large amount of RAM (e.g., 64GB or more), the -g flag simplifies the output by showing all values in gibibytes. This prevents the numbers from becoming excessively large and maintains readability.
Example 5: free -s 2
# Continuously poll and display memory usage every 2 seconds
free -s 2
Explanation: The -s (seconds) flag transforms free into a monitoring tool by repeatedly executing the command at a defined interval. This example refreshes the memory statistics every two seconds, which is ideal for observing memory changes in real-time while an application is running.
Example 6: free -c 5
# Display the memory report a specific number of times
free -c 5
Explanation: To get a few snapshots of memory usage without continuous polling, use the -c (count) flag. This command will print the memory report five times and then exit, which is useful for capturing memory behavior during a specific, short-running task.
Example 7: free -t
# Add a total line that sums RAM and swap space
free -t
Explanation: The -t flag adds a "Total" line to the output. This line displays the sum of the physical memory (Mem) and swap space, providing a combined overview of the total virtual memory capacity available to the system.
Example 8: free --wide
# Display a wide output format showing buff/cache separately
free --wide
Explanation: The --wide option provides a more detailed view by separating the buff/cache column into its two constituent parts: buffers and cache. This can be valuable for advanced troubleshooting to understand exactly how the kernel is using memory for I/O operations.
UNIX/Linux Command Variations
While the free command is standard on RHEL and other Linux distributions, traditional UNIX systems often use different utilities to check memory.
# Use vmstat to get a basic memory overview
vmstat 1 2
Explanation: On Solaris, vmstat is commonly used to report virtual memory statistics. This command will provide a summary of memory, swap, and other system metrics, updating once per second for two iterations.
FreeBSD:
# Use sysctl to view the amount of physical memory
sysctl hw.physmem
Explanation: FreeBSD users often query system control (sysctl) variables directly. The hw.physmem variable specifically holds the value for the total amount of physical RAM in bytes.