Linux free Command Examples

The free command in Linux displays information about system memory usage, including total, used, free, shared, and cached memory. Below are 10 examples demonstrating various uses of the free command with detailed explanations.

Example 1: Basic Memory Usage

free

Displays memory usage in a default format (usually in kilobytes). It shows total, used, free, shared, buff/cache, and available memory for both physical and swap memory.

Sample Output:

              total        used        free      shared  buff/cache   available
Mem:        8048052     2345678     1234567      345678     4467899     5432100
Swap:       2097148       12345     2084803

Example 2: Display in Megabytes

free -m

Shows memory usage in megabytes instead of the default kilobytes for easier readability.

Sample Output:

              total        used        free      shared  buff/cache   available
Mem:           7859        2294        1206         337        4358        5304
Swap:          2047          12        2035

Example 3: Display in Gigabytes

free -g

Displays memory usage in gigabytes, useful for systems with large amounts of RAM.

Sample Output:

              total        used        free      shared  buff/cache   available
Mem:              7           2           1           0           4           5
Swap:             2           0           2

Example 4: Human-Readable Format

free -h

Shows memory usage in a human-readable format, automatically scaling units (e.g., KB, MB, GB) based on size.

Sample Output:

              total        used        free      shared  buff/cache   available
Mem:           7.7G        2.2G        1.2G        337M        4.2G        5.1G
Swap:          2.0G         12M        2.0G

Example 5: Continuous Monitoring

free -s 2

Runs free every 2 seconds, continuously updating the output. Useful for real-time memory monitoring.

Sample Output: Updates every 2 seconds with output similar to the basic free command.

Example 6: Display Total Memory Only

free -t

Includes a total line that sums physical and swap memory.

Sample Output:

              total        used        free      shared  buff/cache   available
Mem:        8048052     2345678     1234567      345678     4467899     5432100
Swap:       2097148       12345     2084803
Total:     10145100     2358023     3319370

Example 7: Wide Format Output

free -w

Displays output in a wide format, separating buffers and cache into distinct columns for clarity.

Sample Output:

              total        used        free      shared    buffers     cache   available
Mem:        8048052     2345678     1234567      345678      123456    4344443     5432100
Swap:       2097148       12345     2084803

Example 8: Display Memory in Bytes

free -b

Shows memory usage in bytes, providing the most granular unit of measurement.

Sample Output:

              total        used        free      shared  buff/cache   available
Mem:     8241415168  2403569152  1264840704   354375680  4573008384  5564661760
Swap:    2148532224     12648448  2135883776

Example 9: Count Number of Updates

free -c 5

Runs free 5 times with a 1-second interval between each run, then stops.

Sample Output: Displays 5 outputs similar to the basic free command, one per second.

Example 10: Combine Options

free -h -t -s 3

Combines options: displays memory in human-readable format, includes a total line, and updates every 3 seconds.

Sample Output: Updates every 3 seconds with output like:

              total        used        free      shared  buff/cache   available
Mem:           7.7G        2.2G        1.2G        337M        4.2G        5.1G
Swap:          2.0G         12M        2.0G
Total:         9.7G        2.2G        3.2G

Note: The free command output may vary slightly depending on the Linux distribution and version. Always check the man page (man free) for additional options and details specific to your system.