If you're like me, and hate having your memory sucked out, and tied up. You struggle to find ways to monitor that. Or kill processes to keep it free.. well look no further. With this simple function you can do just that, are you ready for the magic to begin? I know I am 😊

Olay, log into your server (this does not work in KVM, Β or OpenVZ)

Once logged in.. use your favorite editor, mine just so happens to be nano..

[black@demobox]#: nano ~/.bashrc

Now paste this function at the very end of this file..


function freeram() { sudo su -c 'sync; for i in 1 2 3; do echo $i > /proc/sys/vm/drop_caches; done' ; } # free up memory on the local system


CTRL+X <save>

Then either log out, type source ~/.bashrc or . ~/.bashrc. and type:

free -m && freeram && free -m

You'll get to see the before and after. Pretty nifty huh? Enjoy!