Created
July 21, 2015 12:20
-
-
Save milushov/af55e6d1b60d313a928b to your computer and use it in GitHub Desktop.
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
# Show how much RAM application uses. | |
# $ ram safari | |
# # => safari uses 154.69 MBs of RAM. | |
function ram() { | |
local sum | |
local items | |
local app="$1" | |
if [ -z "$app" ]; then | |
echo "First argument - pattern to grep from processes" | |
else | |
sum=0 | |
for i in `ps aux | grep -i "$app" | grep -v "grep" | awk '{print $6}'`; do | |
sum=$(($i + $sum)) | |
done | |
sum=$(echo "scale=2; $sum / 1024.0" | bc) | |
if [[ $sum != "0" ]]; then | |
echo "${fg[blue]}${app}${reset_color} uses ${fg[green]}${sum}${reset_color} MBs of RAM." | |
else | |
echo "There are no processes with pattern '${fg[blue]}${app}${reset_color}' are running." | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment