2024-03-01
free
Command’s OutputThe simplest way to use the free
command is to type free
into your terminal. This will display a table summarizing memory usage. Let’s break down the key columns:
Example:
A typical output might look like this:
total used free shared buff/cache available
Mem: 993M 214M 631M 160M 147M 736M
Swap: 2002M 51M 1951M
This indicates a system with 993MB of RAM, where 214MB is used, 631MB is free, 160MB is shared between processes, 147MB is in buffers and cache, and 736MB is immediately available. The system also has 2002MB of swap space, with 51MB currently used.
free
Command with OptionsThe free
command offers many options to customize its output:
-h
(or --human-readable
): Displays memory amounts in a human-readable format (e.g., KB, MB, GB), making the output much easier to understand.
-m
(or --mega
): Displays memory amounts in megabytes.
-g
(or --giga
): Displays memory amounts in gigabytes.
-k
(or --kilo
): Displays memory amounts in kilobytes (default).
-b
(or --bytes
): Displays memory amounts in bytes.
-s <interval>
(or --seconds=<interval>
): Continuously updates the display at the specified interval (in seconds). This is extremely useful for monitoring memory usage over time.
Code Examples with Options:
free -h
free -g
free -h -s 2
This continuous monitoring is important for debugging performance issues. You can use Ctrl+C
to stop the continuous output.
By mastering the free
command and its options, you gain a powerful tool for understanding and managing your Linux system’s memory resources. This is essential for optimizing performance and troubleshooting memory-related problems.