Skip to content

Instantly share code, notes, and snippets.

@kathawala
Created November 28, 2014 23:06
Show Gist options
  • Save kathawala/2f64a3d20037f7bb96e7 to your computer and use it in GitHub Desktop.
Save kathawala/2f64a3d20037f7bb96e7 to your computer and use it in GitHub Desktop.
Little script to print out your memory usage
#!/bin/bash
# free is a utility which provides statistics about memory in use
# -m flag provides memory in Mb
# awk takes all the arguments from grep and can print them
USED=`free -m | grep cache: | awk '{print $3}'`
TOTAL=`free -m | grep Mem: | awk '{print $2}'`
# bc is a linux calculator which can print floating point
# scale determines number of decimals (ex: 0.00)
printf "%.2f%%\n" $(bc <<< "scale=5; $USED*100/$TOTAL")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment