Skip to content

Instantly share code, notes, and snippets.

@Prince781
Last active August 29, 2015 14:11
Show Gist options
  • Save Prince781/f5f2d375de9d841d0c2b to your computer and use it in GitHub Desktop.
Save Prince781/f5f2d375de9d841d0c2b to your computer and use it in GitHub Desktop.
file size function
#!/bin/sh
# put this in .bashrc or /etc/bashrc
function fsize() {
kB=1000
val=$(stat --printf="%s" $1)
if [ $val -lt $kB ]; then
printf "$val B\n"
elif [ $val -lt $(($kB*$kB)) ]; then
printf "%0.2lf KB\n" $(bc -l <<< "$val/$kB")
elif [ $val -lt $(($kB*$kB*$kB)) ]; then
printf "%0.3lf MB\n" $(bc -l <<< "$val/($kB^2)")
else
printf "%0.3lf GB\n" $(bc -l <<< "$val/($kB^3)")
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment