fastdu counter together with sizes

This commit is contained in:
ville rantanen
2018-10-25 16:30:59 +03:00
parent 608aac1871
commit a572f0334b

View File

@@ -33,16 +33,16 @@ function siprefix() {
# Return a SI prefixed string from integer # Return a SI prefixed string from integer
[ "$1" = "0" ] && { [ "$1" = "0" ] && {
echo "0 " echo "0 #"
return 0 return 0
} }
awk 'BEGIN{ x = '$1' awk 'BEGIN{ x = '$1'
split("_ k M G T P E Z",type) split("# k# M# G# T# P# E# Z#",type)
for(i=7;y < 1;i--) for(i=7;y < 1;i--)
y = x / (10^(3*i)) y = x / (10^(3*i))
str=int(y*10)/10 " " type[i+2] str=int(y*10)/10 " " type[i+2]
if (i==-1) { str = x " " } if (i==-1) { str = x " #" }
print str print str
}' || return $? }' || return $?
} }
@@ -58,27 +58,20 @@ function animate() {
} }
function processfolder() { function processfolder() {
if [[ "$COUNT" -eq 1 ]]; then
countfiles "$@"
else
displaysize "$@"
fi
}
function countfiles() { SIZECOUNT=( $( find "$@" -type f -printf %s"\n" 2>/dev/null | awk '{ sum += $1; count += 1 } END { print int(sum)+0 , int(count)+0 }' ) )
SIZE=$( find "$@" -type f -printf %s"\n" 2>/dev/null | awk '{ sum += 1 } END { print int(sum)+0 }' ) SIZE=${SIZECOUNT[0]}
[[ "$HUMAN" -eq 1 ]] && {
SIZE=$( siprefix "$SIZE" )
}
echo "${SIZE}"
}
function displaysize() {
SIZE=$( find "$@" -type f -printf %s"\n" 2>/dev/null | awk '{ sum += $1 } END { print int(sum)+0 }' )
[[ "$HUMAN" -eq 1 ]] && { [[ "$HUMAN" -eq 1 ]] && {
SIZE=$( filesize "$SIZE" ) SIZE=$( filesize "$SIZE" )
} }
echo "$SIZE" [[ "$COUNT" -eq 1 ]] && {
COUNTS=${SIZECOUNT[1]}
[[ "$HUMAN" -eq 1 ]] && {
COUNTS=$( siprefix "$COUNTS" )
}
}
echo -e "$SIZE\t$COUNTS"
} }
# Get options # Get options
@@ -109,21 +102,24 @@ fi
if [[ "$ANIMATE" -eq 1 ]]; then if [[ "$ANIMATE" -eq 1 ]]; then
animate & animate &
fi fi
[[ "$HUMAN" -eq 1 ]] && NUMFORMAT="%5s %2s "
[[ "$HUMAN" -ne 1 ]] && NUMFORMAT="%d\t"
[[ "$COUNT" -eq 1 ]] && NUMBERS="$NUMFORMAT$NUMFORMAT"
[[ "$COUNT" -ne 1 ]] && NUMBERS="$NUMFORMAT"
[[ "SUMMARY" -eq 1 ]] && FORMAT="$NUMBERS\n"
[[ "SUMMARY" -ne 1 ]] && FORMAT="$NUMBERS %s\n"
if [[ "$SUMMARY" -eq 1 ]]; then if [[ "$SUMMARY" -eq 1 ]]; then
# Display one line # Display one line
processfolder "${what[@]}" processfolder "${what[@]}" | xargs printf "$FORMAT"
else else
if [[ "$HUMAN" -eq 1 ]]; then
FORMAT="%8s %s\n"
else
FORMAT="%d\t%s\n"
fi
# One size for each argument # One size for each argument
for dir in "${what[@]}"; do for dir in "${what[@]}"; do
printf "$FORMAT" "$( processfolder "$dir" )" "$dir" printf "%s %s\n" "$( processfolder "$dir" )" "$dir" | xargs printf "$FORMAT"
done done
fi fi
if [[ "$ANIMATE" -eq 1 ]]; then if [[ "$ANIMATE" -eq 1 ]]; then
kill %1 kill %1
fi fi