blob: a6e9d5f6e06abe1c19427ae0f47fea1c3186be7d (
plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#!/bin/bash
DF="/usr/bin/df"
DU="/usr/bin/du"
usage() {
echo 'usage: dup [OPTION] DEVICE...'
echo
echo ' -p print given prefix at the begin of each line'
echo ' -h display this help and exit'
exit
}
while getopts ":hp:" optname; do
case "$optname" in
"p")
prefix=$OPTARG
;;
"h")
usage
;;
"?")
echo "Unknown option $OPTARG"
usage
;;
":")
echo "No argument value for option $OPTARG"
;;
*)
echo "Unknown error while processing options"
;;
esac
done
IFS=$"NUL"
declare -a args=${@:$OPTIND}
[[ ${args:0} ]] || args="."
for device in $args; do
if ! [[ "$($DU "$device")" ]]; then
usage
fi
done
for device in $args; do
size="$($DF "$device" --output=size | tail --lines=+2)"
used="$($DU -s "$device" | tr '\t' '\n' | head --lines=1)"
usedh="$($DU -sh "$device" | tr '\t' '\n' | head --lines=1)"
sizeh="$($DF -h "$device" --output=size | tail --lines=+2)"
misc="$usedh$sizeh"
title="$prefix$device"
pbar -n $used $size "$title" "$misc"
done
|