BASH Memory

From Indie IT Wiki
Jump to: navigation, search

HOWTO: INFO:

Display True Memory Usage

Most people use the free command to show RAM usage, but read it wrong. In the example below, it looks like the computer only has 67 MB available. However, Linux keeps data stored in RAM when reading disks and some more for programs just in case they need it, effectively being greedy for better performance.

What the Linux system is actually using or needs to use is shown on the 3rd line!

free -m
         total      used     free   shared     buffers     cached
Mem:      4049      3982       67        0          16       3530
-/+ buffers/cache:   435     3614
Swap:     6142        53     6088

So, a slightly tweaked command would be...

free -m | awk 'NR==3 {print $4 " MB free."}'
3614 MB free.

(The above command for awk translates to "print 4th column of third line" :-)

Thanks to Thoughts by Clag G.

HOWTO: INSTALL:

ps_mem

sudo -i
cd /tmp
wget https://raw.githubusercontent.com/pixelb/ps_mem/master/ps_mem.py
sudo chmod +x ps_mem.py
sudo cp -av ps_mem.py /usr/local/bin/psmem
exit
which psmem

Usage

sudo psmem
sudo psmem | grep -E thunderbird

For more information see the GitHub page, and thanks to Epety ET.