Created
November 28, 2014 23:06
-
-
Save kathawala/2f64a3d20037f7bb96e7 to your computer and use it in GitHub Desktop.
Little script to print out your memory usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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