Linux free command options
The free
command in Linux is used to display information about the system's memory usage, including RAM and swap space. It has several options that allow you to customize the output format and the level of detail. Here's a breakdown of the commonly used options with examples and their output.
Basic Syntax:
1. -h
(Human-readable format):
- Purpose: Displays the memory usage in a human-readable format, automatically adjusting the unit (KB, MB, GB, etc.) depending on the size of the memory.
Example:
Output:
- Gi (Gibibytes) and Mi (Mebibytes) are used for clarity, and the memory values are shown in the most suitable unit.
2. -m
(Show in Megabytes):
- Purpose: Displays the memory usage in megabytes (MB) instead of the default kilobytes (KB).
Example:
Output:
- Memory values are displayed in megabytes (MB), making it easier to read when working with larger systems.
3. -g
(Show in Gigabytes):
- Purpose: Displays the memory usage in gigabytes (GB).
Example:
Output:
- This output uses gigabytes (GB) for a higher-level view of memory usage.
4. -t
(Show total memory):
- Purpose: Displays a summary line that includes the total memory (physical + swap). This line adds up the physical memory and swap space, providing a more comprehensive total memory usage.
Example:
Output:
- The
Total:
line at the bottom adds together the memory from both the physical RAM (Mem:
) and swap (Swap:
).
5. -c <count>
(Repeat output count
times):
- Purpose: Repeats the
free
command output a specified number of times (useful for monitoring memory usage over time).
Example:
Output:
- The
free
command will display the memory usage five times (or however many times you specify) with the same data.
6. -s <seconds>
(Set delay between updates):
- Purpose: Displays memory usage repeatedly with a specified delay between each update in seconds.
Example:
Output (example):
- This shows the memory usage every 5 seconds.
7. -w <delay>
(Set update delay for seconds in batch mode):
- Purpose: Set the delay in seconds between updates when used in batch mode (
-b
).
Example:
Output:
- This will show the memory usage with a 1-second delay between each update, but in batch mode, which is not interactive.
8. -V
(Version):
- Purpose: Display the version of the
free
command.
Example:
Output:
- This will display the version of the
free
command installed on your system.
Summary of Common Options:
-h
: Human-readable format (e.g., GB, MB, KB).-m
: Display memory in megabytes (MB).-g
: Display memory in gigabytes (GB).-t
: Show total memory (including swap).-c <count>
: Repeat output for a specified number of times.-s <seconds>
: Delay between updates in seconds (repeated output).-w <delay>
: Set update delay for batch mode.-V
: Show the version of thefree
command.
The free
command provides an easy-to-understand snapshot of system memory and swap usage, and the options help tailor the output to your needs, whether you prefer more detailed, readable formats or a summary of the memory usage over time.