Linux command free - check the amount of free and occupied RAM

  • Last updated: Oct 25, 2024
  • Views: 22
  • Author: Admin

If you work as a system administrator in some company, sometimes in the work there may be a need to check the current amount of RAM on your Linux server, for example, you need to see how much RAM is currently used by the system. Knowledge of the current state of RAM in Linux will be useful in identifying bottlenecks in the system, for monitoring performance or optimizing the work of services.

One of the easiest ways to get information about the state of RAM in Linux is to use the free command. The free command displays information about the total, used and free RAM in Linux, as well as data on swap memory. Swap is a type of memory that is used to store temporary data, and it is used only when there is not enough main RAM in the system.

In this article, we will look at how to use the free command to view the amount of available and used RAM, and we will also decipher the main parameters of the command.

To make sure that the free command works the same on absolutely all Linux platforms, we will provide images with the output of the command on Ubuntu, Centos, Fedora, Debian, Oracle Linux platforms.

 

Command syntax:

free [options]

Parameters:

-b - Outputs data in bytes.

-k - Outputs data in kilobytes.

-m - Displays data in megabytes.

-g - Displays data in gigabytes.

-h - Outputs data in a human-readable format.

-t - Adds another line to the end with the total memory amount.

-s - Updates information about RAM at the specified interval in seconds.

-c - The number of times to update the RAM information is determined by using the command together with the -s parameter.


 

Descriptions of columns with data returned by the free command:

total - The total amount of RAM installed on the server.

used - The amount of RAM used.

free - Amount of free RAM.

shared - The amount of RAM used for shared processes.

buffers/cache - The amount of RAM used for buffers and cache.

available - Available RAM for use.

 

Examples of free command column output.

centos command free

Example output of the free command on Centos.

 

debian command free

Example output of the free command on Debian.

 

fedora command free

Example output of the free command on Fedora.

 

oraclelinux command free

Example output of the free command on Oracle Linux.

 

ubuntu command free

Example output of the free command on Ubuntu.


 

Examples of the free command.

1. The first use case is to call the command with the -b parameter.

~$ free -b

As a result, you will receive data on RAM in bytes. This output option can be useful if you need an accurate idea of ​​the amount of memory in the system.

centos command free -b

Example output of the free command with the -b parameter on Centos.

 

debian command free -b

Example output of the free command with the -b parameter on Debian.

 

fedora command free -b

Example output of the free command with the -b option on Fedora.

 

oraclelinux command free-b

Example output of the free command with the -b parameter on Oracle Linux.

 

ubuntu command free -b

Example output of the free command with the -b parameter on Ubuntu.


 

2. The second option is to call the command with the -k parameter.

~$ free -k

In this case, you will receive data in kilobytes. By default, the free command provides data in kilobytes, so you can call the command without passing this parameter.

centos command free -k

Example output of the free command with the -k parameter on Centos.

 

debian command free -k

Example output of the free command with the -k parameter on Debian.

 

fedora command free -k

Example output of the free command with the -k parameter on Fedora.

 

oraclelinux command free -k

Example output of the free command with the -k parameter on Oracle Linux.

 

ubuntu command free -k

Example output of the free command with the -k parameter on Ubuntu.


 

3. The third use case is to call the command with the -m parameter.

~$ free -m

As a result of the command execution, the data will be given in megabytes. Data on megabytes may be more convenient to obtain for easy perception.

centos command free -m

Example output of the free command with the -m parameter on Centos.

 

debian command free -m

Example output of the free command with the -m parameter on Debian.

 

fedora command free -m

Example output of the free command with the -m parameter on Fedora.

 

oraclelinux command free -m

Example output of the free command with the -m parameter on Oracle Linux.

 

ubuntu command free -m

Example output of the free command with the -m parameter on Ubuntu.


 

4. The fourth use case is to call the command with the -g parameter.

~$ free -g

In this case, the command will return the result in gigabytes. It is convenient to get the result in gigabytes if you have a lot of RAM installed on your server.

centos command free -g

Example output of the free command with the -g parameter on Centos.

 

debian command free -g

Example output of the free command with the -g parameter on Debian.

 

fedora command free -g

Example output of the free command with the -g option on Fedora.

 

oraclelinux command free -g

Example output of the free command with the -g parameter on Oracle Linux.

 

 

Example output of the free command with the -g parameter on Ubuntu.


 

5. The fifth use case is to call the command with the -h parameter.

~$ free -h

The result will be data in a readable format, the free command will automatically select which unit of measurement to substitute. (bytes, kilobytes, megabytes, gigabytes, etc.).

centos command free -h

Example output of the free command with the -h parameter on Centos.

 

debian command free -h

Example output of the free command with the -h option on Debian.

 

fedora command free -h

Example output of the free command with the -h option on Fedora.

 

oraclelinux command free -h

Example output of the free command with the -h parameter on Oracle Linux.

 

ubuntu command free -h

Example output of the free command with the -h parameter on Ubuntu.


 

6. The sixth use case is to call the command with the -t parameter.

~$ free -t

In this case, at the very end of the output, another line will be added with the total of all RAM.

centos command free -t

Example output of the free command with the -t parameter on Centos.

 

debian command free -t

Example output of the free command with the -t parameter on Debian.

 

fedora command free -t

Example output of the free command with the -t option on Fedora.

 

oraclelinux command free -t

Example output of the free command with the -t parameter on Oracle Linux.

 

ubuntu command free -t

Example output of the free command with the -t parameter on Ubuntu.


 

7. The seventh use case is to call the command with the -s parameter and pass the number of seconds.

~$ free -s 5

The -s parameter and the number after it indicate the number of seconds after which the result will be updated. In the example, I indicated that the output will be updated every 5 seconds. This output option will be very useful if you need memory data for real-time diagnostics.

centos command free -s

Example output of the free command with the -s parameter on Centos.

 

debian command free -s

Example output of the free command with the -s option on Debian.

 

fedora command free -s

Example output of the free command with the -s option on Fedora.

 

oraclelinux command free -s

Example output of the free command with the -s option on Oracle Linux.

 

ubuntu command free -s

Example output of the free command with the -s parameter on Ubuntu.


 

8. The eighth use case is to call the command with the -c parameter.

~$ free -s 5 -c 3

The parameter limits the number of updates and must be used together with the -s parameter. In my example, I specified that I want the memory data to be updated every 5 seconds, but only 3 times.

centos command free -c -s

Example output of the free command with the -s -c parameter on Centos.

 

debian command free -c -s

Example output of the free command with the -s -c option on Debian.

 

fedora command free -c -s

Example output of the free command with the -s -c option on Fedora.

 

oraclelinux command free -c -s

Example output of the free command with the -s -c option on Oracle Linux.

 

ubuntu command free -c -s

Example output of the free command with the -s -c option on Ubuntu.


 

In summary, the free command with various parameters allows you to obtain useful information about the state of RAM and swap memory in real time. The choice of parameters depends on what data you need for your presentations.

I hope my article will help you in some way in your work, and I wish you further successful study of Linux.

 

SIMILAR ARTICLES