Last active
August 29, 2015 14:11
-
-
Save Prince781/f5f2d375de9d841d0c2b to your computer and use it in GitHub Desktop.
file size function
This file contains hidden or 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/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