Check Linux memory usage with 5 command line tools

Sometimes we need to check Linux memory usage, there are many GUI tools like KSysGuard or GNOME system monitor. But here we are focusing on the CLI tools, which could be used with shell scripts, over SSH, serial port or whenever a GUI is not available.

Amount of available memory keeps changing quickly between used, free, shared, buffers and cached, though total amount memory in a system is fixed, let’s start.


1. Check with the free command

One of the most used command to check memory usage in Linux or any UNIX like OS, even available in most embedded systems.

Just run the command like bellow, no root privilege required.


It’s worth to pass few more command line arguments to get more convenient results.

  1. -h , in human readable form
  2. -b , results in bytes
  3. -k , results in KB
  4. -m , results in MB
  5. -c , display results many times,1 second delay
  6. -s , continuously print results with  a delay.


 free -h -c 10 -s 0.5 

Show memory usage in human readable form for 10 times with 0.5 second interval between results.


2. From the /proc/meminfo file

Reading memory usage from this file is specially useful for scripting purpose. All results available in this file are formatted into multiples of KB , use cat , grep, awk or your favorite text manipulation command to get the desired result.

 grep -i 'MemTotal:'  /proc/meminfo 
grep -iE 'MemFree:|SwapTotal:'  /proc/meminfo 
awk -F 'MemFree:'  '{print$2}' < /proc/meminfo  | tr -s 'n'

There could be come


3. Check with the dmidecode command

This command is more hardware specific, useful to know about the computer’s hardware without opening it. Use the DMI type 16 and 17  to get the memory related information. This command requires root privilege, examples bellow.

 sudo dmidecode -t 17 

The result is somewhat long, here a little snippet

Handle 0x0022, DMI type 17, 34 bytes
Memory Device
    Array Handle: 0x001B
    Error Information Handle: 0x0024
    Total Width: 64 bits
    Data Width: 64 bits
    Size: 2048 MB
    Form Factor: SODIMM
    Set: None
    Locator: ChannelB-DIMM0
    Bank Locator: BANK 2
    Type: DDR3
    Type Detail: Synchronous
    Speed: 1333 MHz
    Manufacturer: Kinston
    Serial Number: 8316C2B7
    Asset Tag: 0123456789
    Part Number: ACR256X64D3S1333C9
    Rank: Unknown
    Configured Clock Speed: 1333 MHz

This command is particularly useful for RAM upgrade and hardware related troubleshooting purpose, some more useful dmidecode commands here.

Note: Actual available memory is always less than the amount get from the dmidecode command.


4. Check memory usage with the atop command

Atop is a CLI system monitor could be used to check linux memory usage info including per process usage. Install it on any Debian based distro,

sudo apt-get install atop

Use the -m command line argument to get memory related info, this command prefers to be run as super user.

 sudo atop -m 

Atop considers RAM usage more than 90% as critical.


5. Top and htop commands

Both top and htop are interactive process and system resource viewer, while the htop provides a ncurses based colorful interface. Top is installed in mots system by default, you may need to install htop, on any De bian based distro install it with

 sudo apt-get install htop 

You may want to decrease the update interval of top and htop, for a 0.5 second update interval use the command bellow

 top -d 0.5 
 htop -d 5 



It’s normal that Linux using some more memory than expected, but it’s normal, this extra memory is for caching purpose to make the system more responsive, there is a dedicated site for this, Linux ate my RAM!.

So that’s it, how to check linux memory usage with command line tools. If you have any suggestion or question, just drop a comment, I’ll be happy to hear from you.

Leave a Reply

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