How to Check Memory Usage in Linux (Ubuntu)

  • Home
  • Blog
  • How to Check Memory Usage in Linux (Ubuntu)
display ram usage linux
DateFeb 6, 2025

display ram usage linux

Monitoring memory utilization in Linux is important for preserving device overall performance, troubleshooting slowdowns, and making sure programs have enough assets. Ubuntu, like different ubuntu check what is using memory distributions, gives multiple ways to test reminiscence usage—each from the command line and graphical gear. Whether you need a brief review or distinct insights into which processes are ingesting reminiscence, Linux offers built-in linux see memory usage commands to assist.

Why Check Memory Usage?

Understanding how your system utilizes RAM is crucial for:

  • Identifying memory-hungry processes
  • Diagnosing performance issues
  • Preventing system crashes due to excessive memory consumption
  • Optimizing resource allocation for applications

Commands to Check Memory Usage in Linux

free Command – Displays an overview of RAM usage.
bash
CopyEdit
free -h

  1. The -h flag provides human-readable output (MB/GB).

top Command – Monitors real-time memory usage and active processes.
bash
CopyEdit
top

  1. Press Shift + M to sort processes by memory consumption.

htop Command – A more user-friendly alternative to top.
bash
CopyEdit
htop

  1. (Install with sudo apt install htop if not available).

vmstat Command – Provides memory, CPU, and system performance stats.
bash
CopyEdit
vmstat -s

ps Command – Lists processes and their memory usage.
bash
CopyEdit
ps aux –sort=-%mem | head

  1. This sorts processes by memory usage, showing the top consumers.

/proc/meminfo File – Displays detailed memory statistics.
bash
CopyEdit
cat /proc/meminfo

GUI-Based Memory Monitoring

If you prefer a graphical interface, use:

  • GNOME System Monitor (gnome-system-monitor)
  • KSysGuard (for KDE environments)

Checking Memory Usage with Command-Line Tools in Linux

Monitoring memory usage in Linux is essential for ensuring system performance and identifying check memory in linux resource-intensive processes. Ubuntu and other Linux distributions provide several Linux see memory usage command-line tools to check RAM usage, analyze memory consumption, and troubleshoot performance issues.

1. Using the free Command

The free command provides a quick overview of total, used, and available memory. Run:

bash

CopyEdit

free -h

The -h option displays values in a human-readable format (e.g., MB, GB). The output includes:

  • Total memory installed on the system
  • Used memory currently in use
  • Free memory available for new processes
  • Buffers/cache (memory used for disk caching)ubuntu check what is using memory
2. Using top to View Real-Time Memory Usage

The top command shows system resource usage in real time, including CPU and memory consumption by processes.

bash

CopyEdit

top

Look at the %MEM column to identify processes consuming the most RAM. To sort by memory usage, press Shift + M.

3. Using htop for an Enhanced View

htop is an interactive tool that provides linux see memory usage a more user-friendly display of processes and their memory usage. Install it using:

bash

CopyEdit

sudo apt install htop

htop

It allows easy navigation and sorting of processes by memory usage.

4. Using vmstat for Memory Statistics

The vmstat command provides detailed information about memory, CPU, and disk activity.

bash

CopyEdit

vmstat -s

It displays total memory, used memory, active/inactive memory, and swap usage.

5. Checking Memory Usage by Processes with ps

To list processes consuming the most memory, use:

bash

CopyEdit

ps aux –sort=-%mem | head -10

This command sorts processes by memory usage in descending order and shows the top 10.

6. Analyzing Memory with /proc/meminfo

For detailed memory statistics, check the /proc/meminfo file:

bash

CopyEdit

cat /proc/meminfo

This file contains data about total memory, free memory, available memory, and more.

Using the free Command to Check Memory Usage in Linux

Monitoring memory usage is crucial for maintaining a stable and efficient Linux system. One of the most check memory in linux commonly used tools for this purpose is the free command. It provides a quick Ubuntu check of memory snapshot of RAM and swap usage, helping you diagnose performance issues.

Checking Memory Usage with free

The free command displays memory statistics, including total, used, and available memory. Run the following command in the terminal:

bash

CopyEdit

free -h

Explanation of Output

When you run free -h, you will see output like this:

vbnet

CopyEdit

              total        used        free      shared  buff/cache   available

Mem:           15Gi        4Gi         2Gi        1Gi         9Gi         10Gi

Swap:          2Gi         0Gi         2Gi

  • total: Total installed RAM.
  • used: Memory currently in use.
  • free: Unused memory available for new processes.
  • shared: Memory shared between processes.
  • buff/cache: Memory used by kernel buffers and cache.
  • available: Estimated memory available for new applications without swapping.

Adding the -h flag makes the output human-readable by converting values into MB or GB instead of bytes.

Alternative Ways to Check Memory Usage

1. Using top or htop

The top command provides real-time memory usage:

bash

CopyEdit

top

For a more user-friendly display, install and use htop:

bash

CopyEdit

sudo apt install htop

htop

2. Checking Memory Usage per Process

To find out which processes are consuming the most memory, use:

bash

CopyEdit

ps aux –sort=-%mem | head -10

This command sorts processes by memory usage, displaying the top 10 memory-consuming processes.

3. Using vmstat for Memory Monitoring

The vmstat command provides system performance details, including memory usage:

bash

CopyEdit

vmstat -s

This command shows memory statistics, such as free and active memory, swap usage, and buffer sizes.

Monitoring Memory Usage in Ubuntu with top and htop

Effective memory management is crucial for maintaining optimal system performance, especially on Ubuntu or any Linux-based operating system. Whether you are troubleshooting performance issues, analyzing resource consumption, or simply keeping an eye on your system’s health, monitoring RAM usage is essential.

In this guide, we will explore how to check memory usage in Linux using the top and htop commands.


1. Checking Memory Usage with top

The top command is a built-in system monitoring tool that provides a real-time view of system resource usage, including CPU, memory, and running processes. It is available by default on most Linux distributions, including Ubuntu.

Running top

To start monitoring memory usage, open a terminal and type:

bash

CopyEdit

top

Once the top interface loads, you will see a continuously updating list of processes and their resource usage. The key section display ram usage linux related to memory usage is near the top, which looks something like this:

yaml

CopyEdit

MiB Mem :  7973.0 total,  2612.4 free,  3042.1 used,  2318.5 buff/cache

MiB Swap:  2048.0 total,  1024.0 free,  1024.0 used.  1536.5 avail Mem

Understanding the Memory Fields

The top command provides a breakdown of memory usage:

  • Total Memory (total) – The total amount of RAM available.
  • Free Memory (free) – The amount of RAM that is completely unused.
  • Used Memory (used) – The portion of RAM actively being used by processes.
  • Buffer/Cache (buff/cache) – Memory that is being used for caching but can be freed if needed.

The swap memory section provides details about swap usage:

  • Total Swap (total) – Total available swap space.
  • Free Swap (free) – Unused swap space.
  • Used Swap (used) – Swap currently in use.

To quit top, press q.

Sorting by Memory Usage in top

By default, top sorts processes by CPU usage. To sort by memory usage, press:

  • Shift + M (uppercase “M”) – Sorts processes by memory consumption.

This helps identify which processes are using the most RAM.


2. Using htop for Better Memory Visualization

While top is powerful, htop is a more user-friendly alternative that provides a color-coded, interactive interface.

Installing htop

If htop is not installed by default, you can install it with:

bash

CopyEdit

sudo apt update

sudo apt install htop

Running htop

Start htop by typing:

bash

CopyEdit

htop

You will see a graphical representation of CPU and memory usage at the top of the screen, followed by a list of running processes. Unlike top, htop allows you to scroll through the list of processes using arrow keys.

Understanding Memory Usage in htop

The memory usage bar is displayed near the top:

css

CopyEdit

Mem[#######–] 4.2G/8.0G

Swp[——] 0.0G/2.0G

  • The green bar represents used memory.
  • The blue bar represents buffers.
  • The yellow/orange bar represents cached memory.
  • The swap bar shows how much swap space is being used.

Sorting Processes by Memory Usage in htop

To sort processes by memory usage:

  1. Press F6 to open the sorting menu.
  2. Select %MEM to sort by memory usage.

Alternatively, you can press Shift + M to quickly sort by memory consumption.

Killing a Process in htop

If a process is consuming too much memory and you need to terminate it:

  1. Select the process using arrow keys.
  2. Press F9 to bring up the kill menu.
  3. Select SIGTERM (15) or SIGKILL (9) to terminate the process.

To exit htop, press q.


3. Checking Memory Usage from the Command Line

Apart from top and htop, there are other simple commands to check memory usage.

Using free

The free command provides a quick summary of memory usage:

bash

CopyEdit

free -m

Output:

yaml

CopyEdit

             total        used        free      shared  buff/cache   available

Mem:           7973        3042        2612        100         2318        5343

Swap:          2048        1024        1024

  • total – Total RAM.
  • used – RAM currently in use.
  • free – Unused RAM.
  • buff/cache – Memory used for disk caching.
  • available – Memory available for new processes.

For a continuously updating view, use:

bash

CopyEdit

watch free -m

Using /proc/meminfo

For more detailed memory information, check:

bash

CopyEdit

cat /proc/meminfo

This provides an in-depth breakdown of memory allocation.

Using vmstat

The vmstat command shows memory usage along with CPU and disk statistics:

bash

CopyEdit

vmstat -s

This will display memory stats like total memory, used memory, and swap usage.ubuntu check what is using memory


4. Finding Which Process is Using the Most Memory

To find the top processes consuming RAM, use:

bash

CopyEdit

ps aux –sort=-%mem | head -10

This will list the top 10 processes using the most memory.

Alternatively, using pmap for a specific process ID (PID):

bash

CopyEdit

pmap <PID>

For example, if a process ID is 1234:

bash

CopyEdit

pmap 1234

Analyzing Memory Usage with vmstat in Ubuntu

Efficient memory management is crucial for maintaining optimal system performance in Ubuntu and other Linux-based systems. If your system is running slow or behaving unexpectedly,display ram usage linux checking memory ubuntu check what is using memory usage can help diagnose issues. One of the most powerful tools available for memory analysis is vmstat. This guide will explain how to use vmstat to monitor memory usage, along with other useful Linux commands for checking memory utilization.

Understanding vmstat

The vmstat (Virtual Memory Statistics) command provides real-time system performance metrics, including CPU, memory, disk, and process statistics. It helps administrators diagnose performance bottlenecks by offering a concise snapshot of system resource utilization.

Installing vmstat

Most Linux distributions, including Ubuntu, come with vmstat pre-installed. However, if it’s missing, you can install it using the following command:

bash

CopyEdit

sudo apt update && sudo apt install sysstat

After installation, you can run vmstat using:

bash

CopyEdit

vmstat

This displays a summary of system performance metrics, including memory usage.

Checking Memory Usage with vmstat

To analyze memory usage, use the following command:

bash

CopyEdit

vmstat -s

This provides a detailed summary of memory statistics, including:

  • Total memory
  • Used memory
  • Free memory
  • Active memory
  • Inactive memory
  • Swap memory details

For real-time monitoring, use:

bash

CopyEdit

vmstat 2 5

This updates memory statistics every 2 seconds, running 5 times.

Interpreting vmstat Output

A typical vmstat output looks like this:

bash

CopyEdit

procs ———–memory———- —swap– —–io—- -system– ——cpu—–

 r  b    swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st

 2  0       0  123456  67890  54321    0    0     1     2    3    4  10  5 80  5  0

Key memory-related columns:

  • swpd: Swap memory usage (in KB)
  • free: Free RAM (in KB)
  • buff: Memory used for buffers
  • cache: Cached memory used for faster data access
  • si/so: Swap memory in and out

If so (swap out) is high, your system may be experiencing memory pressure, leading to performance degradation.

Alternative Commands to Check Memory Usage

Apart from vmstat, Linux provides several other commands to check RAM usage and identify memory-intensive processes.

1. free – Display RAM Usage

The free command provides an overview of memory usage:

bash

CopyEdit

free -h

Output example:

bash

CopyEdit

             total        used        free      shared  buff/cache   available

Mem:           16Gi        8Gi        2Gi        1Gi        6Gi       7Gi

Swap:          2Gi        0Gi        2Gi

  • Used: Memory in use
  • Free: Available memory
  • Buff/cache: Memory used for system buffers and caching
  • Available: Estimated memory available for new processes

2. top – View Active Processes Using Memory

Use top to check which processes are consuming the most RAM:

bash

CopyEdit

top

Press Shift + M to sort processes by memory usage.

3. htop – Interactive Memory Monitoring

htop provides a more user-friendly and interactive way to check memory usage:

bash

CopyEdit

sudo apt install htop

htop

4. ps – Check Specific Process Memory Usage

To find memory usage of specific processes, use:

bash

CopyEdit

ps aux –sort=-%mem | head -10

This shows the top 10 memory-consuming processes.

5. smem – Analyze Memory Usage by Processes

For detailed per-process memory statistics, install smem:

bash

CopyEdit

sudo apt install smem

smem -tk

6. dmidecode – View Physical RAM Information

To check installed RAM details:

bash

CopyEdit

sudo dmidecode -t 17

7. /proc/meminfo – View System Memory Information

bash

CopyEdit

cat /proc/meminfo

This displays detailed memory statistics.

Detecting Memory Issues

  • High swap usage (swpd in vmstat): If swap usage is increasing, your system may be running out of RAM.
  • Low available memory (free -h): If available memory is consistently low, check running applications.
  • High cache/buffer usage: Linux caches disk data, which might make “used” memory appear high.

Checking Swap and Memory Usage in Linux (Ubuntu)

Efficient memory management is crucial for maintaining system performance on a Linux machine. This guide will help you check swap usage, identify memory-consuming processes, and display RAM usage on Ubuntu


1. Checking Swap Usage

Swap space acts as an overflow for RAM, storing inactive memory pages. You can check swap usage with:

Using swapon Command

bash

CopyEdit

swapon –show

This displays active swap partitions and their usage.

Using free Command

bash

CopyEdit

free -h

This shows total, used, and free memory, including swap space. Example output:

vbnet

CopyEdit

             total        used        free      shared  buff/cache   available

Mem:          7.7Gi       3.2Gi       2.1Gi       0.5Gi       2.4Gi       4.1Gi

Swap:         2.0Gi       0.5Gi       1.5Gi

Using top or htop

Run top or install htop for a real-time view:

bash

CopyEdit

top

or

bash

CopyEdit

htop

This shows active processes using swap.


2. Checking RAM Usage

Using vmstat

bash

CopyEdit

vmstat -s

Displays detailed memory statistics.

Using cat /proc/meminfo

bash

CopyEdit

cat /proc/meminfo

This provides an extensive breakdown of memory usage.

Using ps to Find High Memory Processes

bash

CopyEdit

ps aux –sort=-%mem | head -10

This lists the top 10 processes consuming the most memory.


3. Graphical Memory Monitoring

If you prefer a GUI, you can install gnome-system-monitor:

bash

CopyEdit

sudo apt install gnome-system-monitor

Run it with:

bash

CopyEdit

gnome-system-monitor

It provides an intuitive display of RAM and swap usage.

Managing Memory Resources in Ubuntu

Efficient memory management is crucial for system performance in Ubuntu. To monitor and manage ubuntu check what is using memory memory usage, Linux provides several command-line tools:

Check What is Using Memory
Use the top or htop command to see real-time memory consumption by processes:
bash
CopyEdit
top

or
bash
CopyEdit
htop

  1. (Install htop with sudo apt install htop if not available.)

Display RAM Usage
Use the free command to check available and used memory:
bash
CopyEdit
free -h

  1. The -h flag displays values in a human-readable format.

See Detailed Memory Usage
Use the vmstat command:
bash
CopyEdit
vmstat -s

  1. It provides a breakdown of total, used, and available memory.

Check Memory per Process
The ps command helps identify high-memory processes:
bash
CopyEdit
ps aux –sort=-%mem | head -10

  1. This lists the top 10 processes consuming memory.

Using Graphical Tools for Memory Monitoring in Linux (Ubuntu)

Monitoring memory usage in Ubuntu is crucial for system performance. While command-line tools like free -m and top are useful, graphical tools provide an intuitive way to visualize memory consumption.

System Monitor – Ubuntu’s built-in GNOME System Monitor (gnome-system-monitor) displays RAM usage, swap memory, and running processes in a user-friendly interface. Open it via the application menu or by running:
bash
CopyEdit
gnome-system-monitor

HTOP – A terminal-based but visually enhanced tool (htop) shows real-time memory and CPU usage with color-coded bars. Install it using:
bash
CopyEdit
sudo apt install htop

htop

KSysGuard – For KDE users, KSysGuard provides detailed memory insights and process management. It can be launched with:
bash
CopyEdit
ksysguard

Bashtop/BPytop – Advanced graphical terminal tools offering interactive memory usage breakdowns. Install with:
bash
CopyEdit
sudo apt install bashtop

bashtop

Automating Memory Monitoring in Ubuntu

Monitoring memory usage in Ubuntu is crucial for maintaining system performance. You can automate memory monitoring using built-in Linux commands and scheduled scripts.

Checking Memory Usage

To see current RAM usage, use:

bash

CopyEdit

free -h

This displays total, used, and available memory in a human-readable format.

To check memory usage per process, use:

bash

CopyEdit

ps aux –sort=-%mem | head -10

This lists the top 10 processes consuming the most memory.

For real-time monitoring, use:

bash

CopyEdit

top

or

bash

CopyEdit

htop  # (install with sudo apt install htop)

Automating with a Script

Create a script to log memory usage:

bash

CopyEdit

#!/bin/bash

echo “Memory Usage on $(date)” >> /var/log/memory.log

free -h >> /var/log/memory.log

ps aux –sort=-%mem | head -10 >> /var/log/memory.log

Make it executable:

bash

CopyEdit

chmod +x memory_monitor.sh

Schedule it via cron:

bash

CopyEdit

crontab -e

Add:

bash

CopyEdit

*/10 * * * * /path/to/memory_monitor.sh

This logs memory usage every 10 minutes.

Automating memory monitoring helps prevent system slowdowns and detect potential issues early. 🚀

Understanding and optimizing memory usage in Linux is essential for maintaining system performance and stability. With tools like free -m, vmstat, top, htop, and ps, you can easily monitor RAM consumption and identify processes using excessive memory. Commands like cat /proc/meminfo provide detailed insights into memory allocation, while smem offers a graphical representation of memory usage.

For Ubuntu users, gnome-system-monitor delivers a user-friendly way to visualize RAM consumption. Additionally, watch -n 1 free -m allows continuous monitoring of memory in real-time. If you encounter high memory usage, consider clearing cached memory using sync; echo 3 > /proc/sys/vm/drop_caches, but use this cautiously as it affects system performance.

By mastering these Linux memory management techniques, you can troubleshoot performance bottlenecks, optimize system resources, and ensure smooth operation.Display ram usage linux Regular monitoring and proactive memory management can prevent slowdowns and improve overall efficiency, making your Linux experience seamless and reliable.

Leave a Reply