Check Memory in Linux

DejaVu Sans MonoIn order to check memory usage in Linux, simply launch a terminal window and type htop

Htop displays a wide array of information, including per-process and total memory usage. Press Ctrl+C or F10 to quit.

If you don’t have htop installed, use top instead.

How To Check Memory in Linux

Why Memory Usage is Important

We know that Linux is the most powerful and important operating system in the field of computer science. Almost all data centers or big companies are using Linux in their backend servers or databases. Basically Linux is commands based operating system but in now a days Linux flavors are providing GUI as well as commands.

► Play

There are many ways to check the memory usage or free memory in Linux using commands. Because when we worked on the server sides we have no GUI that time we worked with commands only. Therefore Linux provides huge set of commands for checking the memory usage in Linux. We will talk about the RAM or SWAP area. Swap area is also memory that we extract from hard drive and use when RAM full and swap the processes with the Swap area memory.

Commands for Checking the Memory in Linux

There are many ways or commands to check memory but we will discuss about some of these.

Free Commands

In Linux free command give us a complete information about the physical memory (RAM) and also provide the information about the swap area and kernel buffers in operating system.

In Linux free command also provide so many options after the “free” word.

For example

free – b           ( Show memory in bytes)

free – k                       ( show memory in kilo Bytes)

free – g           ( show memory in GB gigabytes)

also many flags we can use with free command.

top Command

Another powerful command is top for checking memory information. Top command is used fr memory checking and also provide the information of CPU usage per process. Top command can also be used for to monitor the RAM usage.

htop Command

The working of the htop command is similar top command but it provide the some extra information about the memory RAM and usage of the memory.

Get info from /proc/meminfo file

We can also check the memory usage from the / proc / meminfo file. It is file that will store the all information about the memory usage but it is not the physical memory. / proc / meminfo file store the virtual memory information and not store the real file info. It store the dynamic info that Kernel give the every process.

We use cat command before /proc/meminfo. Cat help us to find the /proc/meminfo file from Kernel files.

vmstat command

Another command for memory checking is vmstat. it works like /proc/meminfo and provide the statistical information about the memory usage.

In the first line vmstat command show the total memory in your system and so on.

How To Check Memory In Linux

 

  1. free command – most simple & easy to use. -m option is for MB

            $ free -m

  1. From /proc/meminfo file

$ cat /proc/meminfo

  1. vmstat command. -s option is to show stats in a single column

$ vmstat -s

  1. top command to check check memory and cpu usage per process

$ top

How to check memory in Linux :

Linux is one of the most popular Operating systems. It is well liked in developer communities and by average users due to the plethora of tools it provides. It is versatile and easy to use. It allows for greater control over the system and allows for monitoring of system resources in a simple manner. There are several commands available to the user that allow to check the memory usage. Some of them are listed below:

Using meminfo:

We can use the meminfo file present in the proc directory to read memory usage. /proc does not hold real files rather it contains virtual files that hold information about the system.

We can read the meminfo file using cat:

The Output displays the total available memory as well as other information.

Using free command:

It is the most widely used command to check memory usage of the system.

It is very simple to use

It will output memory usage in bytes:

We can view the memory usage in MegaBytes(MB) using -m parameter:

It will output memory usage in MegaBytes:

ALternatively we can use the -k and -g parameters to view memory usage in Kilobytes and Gigabytes, respectively.

The -tm parameter can be used to show the total memory available :

Using vmstat command:

We can use the vmstat command to view memory usage in the following way:

The -s flag used for detailed statistics in a single column. The output of the above command will be:

Using top command:

Top provides real-time memory usage statistics. It is dynamic and provides the ability to see memory usage for each running process. It also displays the CPU usage.

The top command is very easy to use just run top in shell:

The output displayed is as follows:

Using dmidecode:

Dmidecode provides detailed information about system RAM. dmidecode parsesthe systems DMI table into a human readable format. The dmidecode command requires administrator privileges. Therefore we need to use the sudo command.

We use the dmidecode command in the following manner:

The dmidecode commands output is very lengthy and the shell generally wont be scroll to view the output completely. So its better to pipe the output to a file.

The output is now saved in the file.txt file. We can view it using nano.

The output is as follows:

Send us a feedback0/500

Do you like this article?
Yes
No