1
0
mirror of https://github.com/nachoparker/btrfs-du.git synced 2024-11-23 17:22:54 +01:00

Add option to output raw bytes in numbers (#24)

Added `-b` option to show size numbers as raw in bytes.
This commit is contained in:
Alexey Murz Korepov 2021-09-07 18:33:39 +03:00 committed by GitHub
parent 239fbb80da
commit dc0194d9f3
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23

@ -20,22 +20,28 @@
# both bytesToHumanIEC, an SI implementatation and test cases for both are at https://gist.github.com/jpluimers/0f21bf1d937fe0b9b4044f21944a90ec
bytesToHumanIEC() {
b=${1:-0}; d=''; s=0; S=(Bytes {K,M,G,T,E,P,Z,Y}iB)
while ((b > 1024)); do
d="$(printf ".%02d" $((b % 1024 * 100 / 1024)))"
b=$((b / 1024))
let s++
done
echo "$b$d${S[$s]}"
if [ "$RAW_NUMBERS" = "1" ]; then
echo "${1}"
else
b=${1:-0}; d=''; s=0; S=(Bytes {K,M,G,T,E,P,Z,Y}iB)
while ((b > 1024)); do
d="$(printf ".%02d" $((b % 1024 * 100 / 1024)))"
b=$((b / 1024))
let s++
done
echo "$b$d${S[$s]}"
fi
}
BTRFS_OPT=""
RAW_NUMBERS=""
while [ ${#} -gt 0 ]; do
case "${1}" in
-h)
echo -en "btrfs-du [-o] <PATH_to_BTRFS-mount>\n\n"
echo -en "btrfs-du [-o] [-b] <PATH_to_BTRFS-mount>\n\n"
echo -en "-o\t\tprint only subvolumes below specified path\n"
echo -en "-b\t\tprint numbers raw (in bytes)\n"
echo -en "-h\t\tprint help\n"
exit 0
;;
@ -43,6 +49,10 @@ while [ ${#} -gt 0 ]; do
BTRFS_OPT=" -o "
shift
;;
-b)
RAW_NUMBERS="1"
shift
;;
*)
LOCATION=${1:-/}
shift