fastdu, and arhiver improvements

This commit is contained in:
Ville Rantanen
2016-02-16 13:34:31 +02:00
parent a48183e19d
commit f131284caa
4 changed files with 59 additions and 12 deletions

39
files/fastdu Executable file
View File

@@ -0,0 +1,39 @@
#!/bin/bash
function helpexit() {
echo "Display file/folder sizes like 'du', but faster and actual byte sizes"
echo "Returns only the size as number"
echo " -h Human readable units"
echo " --help This help"
exit
}
function filesize {
# Return a human readable size from integer of bytes
# Usage: filesize 10000
[ "$1" = "0" ] && {
echo "0 B"
return 0
}
awk 'BEGIN{ x = '$1'
split("B KB MB GB TB PB EB ZB",type)
for(i=7;y < 1;i--)
y = x / (2^(10*i))
str=int(y*10)/10 " " type[i+2]
if (x==0) { str = "0 B" }
print str
}' || return $?
}
[[ -z "$1" ]] && what="."
[[ "$1" = "-h" ]] && { HUMAN=1; shift 1; }
[[ "$1" = "--help" ]] && helpexit
SIZE=$( find $what "$@" -type f -printf %s"\n" | awk '{ sum += $1 } END { print int(sum)+0 }' )
[[ "$HUMAN" -eq 1 ]] && {
filesize "$SIZE"
exit
}
echo $SIZE