-
Notifications
You must be signed in to change notification settings - Fork 14
/
duit.sh
executable file
·28 lines (23 loc) · 742 Bytes
/
duit.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
SEARCH_PATH="${1}"
if [ "${SEARCH_PATH}" == "" ]; then
SEARCH_PATH="."
fi
function process_item()
{
ITEM="$1"
if [ "${ITEM}" == "" ]; then
echo "ERROR"
exit 0
fi
# size in blocks
ITEM_SIZE=$(du -s "${ITEM}" | cut -f 1)
# block size for du is 512 bytes
let ITEM_SIZE=${ITEM_SIZE}*512
# human readable size
ITEM_SIZE_HR=$(awk -v sum="$ITEM_SIZE" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "< 1 Kb"; } ')
# result
printf "${ITEM_SIZE} (${ITEM_SIZE_HR})\t\t${ITEM}\n"
}
export -f process_item
find "${SEARCH_PATH}" -d 1 -exec /bin/bash -c 'process_item "${0}"' {} \; | sort -rn -k1