free Command in Linux
Overview
The 'free' command in Linux is a powerful tool used to display the total amount of free and used memory (RAM) in the system, as well as the buffers and cache used by the kernel. This information is essential for system administrators and users to monitor and manage memory usage.
Linux free Command Syntax
The syntax for the free command is as follows:
Where:
- options: Flags that modify the behavior of the free command.
free Command Options:
- -b: Display memory size in bytes.
- -k: Display memory size in kilobytes (default).
- -m: Display memory size in megabytes.
- -g: Display memory size in gigabytes.
- -h: Display memory size in a human-readable format (e.g., 1K, 234M, 2G).
- -t: Display a line containing the totals.
- -s N: Continuously display the report every N seconds.
- -c N: Display the result N times, then exit. Requires the -s option.
- --help: Display the help message and exit.
- --version: Display version information and exit.
Example Usages
-
Display memory usage in the default format (kilobytes).:
Output:
Explanation: The output shows memory usage in kilobytes, with columns for total, used, free, shared, buffers/cache, and available memory.
-
Display memory usage in a human-readable format.:
Output:
Explanation: The output shows memory usage in a human-readable format, such as M for megabytes and G for gigabytes.
Tips
- Combine the -t option with -h for a more comprehensive and human-readable report.
Advanced Use Cases of free Command in Linux
-
Display memory usage every 5 seconds for a total of 3 times.:
Output:
Explanation: The -s and -c options allow you to monitor memory usage over a period of time and for a specific number of iterations.
-
Display memory usage in gigabytes, with totals.:
Output:
Explanation: The output shows memory usage in gigabytes, and includes a line displaying the total memory for each column.
-
Display memory usage in megabytes, updating every 2 seconds.:
Output:
Explanation: The -s option allows you to monitor memory usage in real-time, with a specified interval between updates.
Conclusion
-
The 'free' command in Linux displays memory usage information.
-
Various options are available to modify the output format and behavior.
-
The -h option provides a human-readable format for easier interpretation.
-
Combining -s and -c options allows monitoring memory usage over time and for a specified number of iterations.