10 ‘free’ Commands to Check Memory Usage in Linux

If you are a Linux user, you may have heard of the term memory usage. Memory usage refers to the amount of memory being used by your computer at any given time. It is an important metric to keep track of, as excessive memory usage can cause your system to slow down or even crash. Fortunately, Linux provides a built-in tool called free that allows you to check your system's memory usage. In this article, we will go over how to use the free command to check memory usage in Linux.

What is the free Command?

The free command is a built-in tool in Linux that displays information about the system's memory usage. It provides detailed information about the amount of memory being used, the amount of free memory available, and the amount of memory being used by the system's kernel.

How to Use the free Command

Using the free command is simple. Just open up a terminal and type free followed by any optional flags. Here's the basic usage

$ free

This will display memory usage statistics for your system.

Understanding the Output

The output of the free command can be overwhelming at first, especially if you're new to Linux. Here's an example output

              total        used        free      shared  buff/cache   available
Mem:        8093816     1439556     5458576      195084     1194684     6159384
Swap:       2097148           0     2097148

Here's what each field means

  • total Total amount of physical memory available to your system.

  • used Amount of memory currently being used by your system.

  • free Amount of memory currently available for use.

  • shared Amount of memory shared between different processes.

  • buff/cache Amount of memory used for disk caching and buffers.

  • available Amount of memory available for new processes to use.

It's important to note that the values displayed in the used field do not include memory used for disk caching. The available field shows the amount of memory that is actually available for new processes, taking into account memory used for disk caching.

10 Useful free Command Options

1. Human-Readable Format (-h)

By default, the free command displays memory usage statistics in bytes. Use the -h flag to display output in a more human-readable format

$ free -h

This displays output using units such as "MB" and "GB" instead of bytes.

2. Continuous Monitoring (-s)

To continuously monitor your system's memory usage, use the -s flag to specify a delay between each update

$ free -s 5

This displays memory usage statistics every 5 seconds.

3. Display Total Line (-t)

The -t flag adds a total line showing the sum of physical memory and swap

$ free -t

4. Display in Megabytes (-m)

Display memory usage statistics in megabytes

$ free -m

5. Display in Gigabytes (-g)

Display memory usage statistics in gigabytes, useful for systems with large amounts of memory

$ free -g

6. Display in Kilobytes (-k)

Display memory usage statistics in kilobytes

$ free -k

7. Display in Bytes (-b)

Display memory usage statistics in bytes

$ free -b

8. Count Updates (-c)

Combine with -s to specify the number of updates before exiting

$ free -s 2 -c 10

This displays memory statistics every 2 seconds for 10 iterations, then exits.

9. Wide Output (-w)

Use the -w flag to produce wide output with separate columns for buffers and cache

$ free -w

10. Combining Multiple Options

You can combine multiple options for customized output

$ free -h -t -s 3

This displays human-readable output with total line, updated every 3 seconds.

Advanced Usage Examples

Memory Usage with Timestamp

$ while true; do date +"%F %T"; free -h; sleep 5; done

This continuously displays memory usage statistics with timestamps, useful for tracking changes over time.

Process-Specific Memory Usage

$ ps aux | grep firefox
$ cat /proc/<PID>/status | grep VmRSS

To check memory usage for a specific process, first find the process ID (PID) using ps, then examine the process status file.

Filtered Output

$ free -h | grep "^Mem"

This displays only the memory line, filtering out swap information.

Understanding Memory Types

Memory Type Description Command
Physical RAM Main system memory free -h
Swap Space Virtual memory on disk free -h | grep Swap
Buffers File system metadata cache free -w
Cache Page cache for files free -w

Conclusion

The free command is an essential tool for monitoring memory usage in Linux systems. With its various options, you can customize the output format, monitor memory continuously, and get detailed insights into your system's memory utilization. Regular memory monitoring helps prevent performance issues and ensures optimal system operation.

Updated on: 2026-03-17T09:01:38+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements