DevOpsLinux

How Can I Check Memory Usage in Linux?

Introduction

You must ensure that your Linux system operates at an optimal level. There are some straightforward commands that let you have access to all relevant details and enable you to monitor memory statistics. With this guide, we have provided simple ways to check memory usage in Linux. At the same time, you will get detailed insights into how these ways can further help you. All the mentioned ways in this guide will work properly with nearly every Linux distribution. Dig into the sections below and get all the details. 

System Requirements

Before you learn the process to check memory usage in Linux, you need to consider the following prerequisites – 

  • Accessibility to a command line or terminal
  • A user that possesses sudo privileges
  • The apt package manager

6 Ways to Check Memory Usage in Linux

6 Ways to Check Memory Usage in Linux

The below-mentioned list includes 6 different processes to check memory usage on Linux. Let’s take a quick glimpse at them!  

Check Memory Usage Using the “top” Command

The “top” command serves as a powerful utility that can be employed to check process memory usage in Linux. It gives real-time details about the processes operating on your system, including CPU usage, check memory usage linux, & other metrics.

Follow the below steps to check memory usage in Linux using the “top” command:

  1. Open a terminal window on your system.
  2. Type “top” and press Enter to launch the “top” command.
Type "top" and press Enter to launch the "top" command.
  1. Wait for a few seconds for the command to begin gathering data.
  2. Look for the “MEM” column in the output. This column displays the amount of physical memory usae linux used by each process, in kilobytes (KB).
Steps to check memory usage in Linux using the "top" command
  1. You can also check the “SWAP” column to see the amount of swap space used by each process, in KB.
Steps to check memory usage in Linux using the "top" command
  1. To sort the output by check memory usage in Linux, press the “M” key. This will arrange the processes in descending order of memory usage.
Steps to check memory usage in Linux using the "top" command
  1. To escape the “top” command, press the “q” key.

Check Memory Usage on Linux with User-friendly Controls Using the “htop” Command

The “htop” command is actually an interactive process viewer when it comes to Linux systems. It provides a human-friendly interface for monitoring system resources, incorporating memory usage. It serves as a more advanced version of the “top” command & enables more intuitive control of processes.

Here is the process to check memory usage in Linux utilizing the “htop” command:

  1. Open a terminal window on your system.
  2. Enter “sudo apt-get install htop” to install “htop” if it is not already installed on your system.
Process to check memory usage in Linux utilizing the "htop" command
  1. Once “htop” is installed, type “htop” and press Enter to launch the “htop” command.
Process to check memory usage in Linux utilizing the "htop" command
  1. Wait for a few seconds for the command to start gathering data.
  2. Look for the “MEM%” column in the output. This column displays the percentage of physical memory used by each process.
Process to check memory usage in Linux utilizing the "htop" command
  1. You can also check the “SWAP%” column to see the percentage of swap space used by each process.
  2. To sort the output by checking memory usage, press the “F6” key, and then select “MEM%” from the list of sorting options.
Process to check memory usage in Linux utilizing the "htop" command
  1. You can also filter the output to show only processes that meet certain criteria. To do this, press the “F4” key, and then enter a search term in the “Filter:” field.
Process to check memory usage in Linux utilizing the "htop" command
  1. To exit the “htop” command, press the “q” key.

Recommended: A Complete Guide to useradd Command in Linux with Examples

Check the Amount of Physical & Swap Memory Free using the “free” Command

The “free” command serves as a utility and displays information about the amount of free & utilized memory in the system, including physical as well as swap memory.

Follow the below steps to check the memory usage in Linux employing “free” command in Linux: 

  1. Open a terminal window on your system.
  2. Type “free” and press Enter to launch the “free” command.
Check the memory usage in Linux employing "free" command in Linux
  1. The output of the command will show the total amount of physical and swap memory, as well as the amount of used and free memory in each category.
Check the memory usage in Linux employing "free" command in Linux
  1. Look for the “Mem” and “Swap” rows in the output. The columns in these rows show the following information:
Check the memory usage in Linux employing "free" command in Linux
  • total: the total amount of physical or swap memory, in kilobytes (KB)
  • used: the amount of physical or swap memory currently in use, in KB
  • free: the amount of physical or swap memory currently available for use, in KB

Check the Virtual Memory Statistics Report Using the “vmstat” Command

The “vmstat” command is also a utility that can be found available with most Linux-based systems. It shows virtual memory statistics, including information about processes, paging, block I/O, and CPU activity.

Here are steps to check the virtual memory statistics report in Linux employing the “vmstat” command:

  1. Open a terminal window on your system.
  2. Type “vmstat” and press Enter to launch the “vmstat” command.
Check the virtual memory statistics report in Linux employing the "vmstat" command
  1. The output of the command will display a series of columns with the following information:
  • procs: the number of processes currently running, waiting, or blocked
  • memory: the amount of free, buffered, and cached memory, as well as the amount of swap space in use
  • swap: the amount of swap space in use and the number of pages swapped in and out
  • io: the number of block input/output (I/O) operations per second and the amount of data transferred per second
  • system: the number of interrupts per second and the number of context switches per second
  • cpu: the percentage of time the CPU is idle, user, system, or waiting for I/O

Check Linux Memory Info Using the “cat” Command

The “cat” command is yet another utility that is available with most Linux-based systems. It is employed to show the contents of files as well as system information. 

Follow the below steps to check memory usage on Linux using the “cat” command:

  1. Open a terminal window on your system.
  2. Type “cat /proc/meminfo” and press Enter to display the memory information.
Check Linux Memory Info Using the "cat" Command
  1. The output of the command will show various lines of information about the system’s check memory usage in Linux, including:
  • MemTotal: the total amount of physical memory in kilobytes (KB)
  • MemFree: the amount of physical memory currently available for use in KB
  • MemAvailable: the estimated amount of physical memory available for starting new applications in KB
  • Buffers: the amount of memory used by the kernel buffers in KB
  • Cached: the amount of memory used by the page cache in KB
  • SwapTotal: the total amount of swap space in KB
  • SwapFree: the amount of free swap space in KB

Check Memory Usage in Linux Using GUI

You can easily check memory usage in Linux with the help of graphical user interfaces (GUI) such as the system monitor tool. The system monitor provides a human-friendly way to monitor the performance of your system, including memory usage.

Here are the quick steps to check memory usage in Linux utilizing GUI:

  1. Open the system monitor tool. This can usually be found in the Applications menu, under System Tools or System Settings, depending on your Linux distribution.
check memory usage in Linux utilizing GUI
  1. In the system monitor tool, click on the Resources tab.
check memory usage in Linux utilizing GUI
  1. Under the Memory section, you will see information about your system’s memory usage, including:
  • Total: the total amount of physical memory in your system
  • Used: the amount of physical memory currently in use by the system
  • Free: the amount of physical memory currently available for use
  • Cached: the amount of memory used by the system for caching disk data
  • Buffers: the amount of memory used by the system for buffering I/O operations

You can also check out more detailed insights about memory usage by clicking on the Memory History button or by selecting the Memory tab. This will show a graphical representation of your system’s memory usage over time.

Also Read: How to Use the xargs Command in Linux?

Summing Up

Once you go through this guide thoroughly, you will learn how to check memory usage in Linux. At the same time, you can apprehend how a single command offers considerable valuable data for future analysis. It is very essential for you to learn to interpret the data or details. All this enables you to administer your web hosting server much more effectively. Moreover, you can reach out to our Hostbillo professionals anytime to get the right solutions to the relevant queries or issues you may face.

Arpit Saini

He is the Chief Technology Officer at Hostbillo Hosting Solution and also follows a passion to break complex tech topics into practical and easy-to-understand articles. He loves to write about Web Hosting, Software, Virtualization, Cloud Computing, and much more.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *