HomeLinuxHow to Check Memory Usage in Linux Using the Command Line (Ubuntu)

How to Check Memory Usage in Linux Using the Command Line (Ubuntu)

When you’re new to Linux, one of the first things you’ll want to know is how to check how much memory (RAM) your system is using, like you would with Task Manager in Windows. This guide shows you the most useful commands to check memory usage from the command line in Ubuntu and other Linux distributions.

how to check memory usage in linux

Open a terminal (press Ctrl + Alt + T in Ubuntu) and try the commands below.

1. free

The free command shows the total, used and free physical memory (RAM) and swap space, as well as the memory used for buffers and cache.

The easiest way to use it is with the -h (human-readable) option, which shows sizes in MB or GB:

free -h

To show values in megabytes, use:

free -m

Free linux command

Look at the available column: it shows how much memory is available for new programs, including memory that Linux is using for cache but can free up when needed.

Other useful options:

  • -b, -k, -m, -g: show values in bytes, kilobytes, megabytes or gigabytes
  • -t: add a line with the total of RAM and swap
  • -s N: repeat the output every N seconds (press Ctrl + C to stop)

2. vmstat

The vmstat command reports information about processes, memory, paging, disk I/O and CPU activity. It’s useful for watching memory usage over time.

vmstat 5

This prints a new line every 5 seconds. To print 10 updates and then stop, use:

vmstat 5 10

vmstat linux command

Other options: -s shows a table of memory statistics and event counters, and -S M shows values in megabytes.

3. top

The top command shows running processes in real time, along with total memory and swap usage at the top of the screen.

top

top linux command

While top is running, press Shift + M to sort processes by memory usage, Shift + P to sort by CPU usage, and q to quit. You can also start it with options, for example top -d 2 to refresh every 2 seconds, or top -p 1234 to monitor only the process with ID 1234.

4. htop (Easier to Read)

htop is a more user-friendly version of top, with colored memory and CPU bars and mouse support. Install it with sudo apt install htop and run:

htop

If you prefer a graphical tool, open the System Monitor app in Ubuntu and go to the Resources tab.

Roshan Karkera
Roshan Karkera
Roshan Karkera is a passionate blogger and a software engineer by profession, driven by a love for technology, science, and continuous learning. With a strong belief in sharing knowledge, he started this blog to inspire and inform readers through simple, insightful content. When he's not coding or exploring the latest in tech, you’ll find him writing about ideas that matter. Connect with him on Twitter or your favorite social platform to stay updated.
RELATED ARTICLES

8 COMMENTS

  1. I am writing to let you understand of the notable experience our princess experienced checking your blog. She noticed a lot of details, most notably how it is like to possess an amazing giving spirit to let a number of people completely know certain tricky things. You undoubtedly did more than our expectations. Thanks for displaying these warm and helpful, dependable, educational not to mention fun guidance on that topic to Janet.

  2. I cannot WAIT to read more of this. I mean, you just know so much about this. So much of it Ive never even thought of. You sure did put a new twist on something that Ive heard so much about. I dont believe Ive actually read anything that does this subject as good justice as you just did.
    fc forex
    [url=http://www.liveinternet.ro/tranzactii-forex-bursa-romania/]roboti forex[/url]
    http://www.liveinternet.ro/tranzactii-forex-bursa-romania/ – cum functioneaza forex

  3. I simply want to mention I am very new to blogging and site-building and absolutely loved this web site. Most likely I’m planning to bookmark your blog . You really come with superb articles. Cheers for sharing your web page.

  4. Excellent job right here. I genuinely enjoyed what you had to say. Keep going because you absolutely bring a new voice to this topic. Not many people would say what youve said and still make it interesting. Well, at least Im interested. Cant wait to see additional of this from you.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular