-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinclear.sh
78 lines (60 loc) · 1.2 KB
/
binclear.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
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
usage() {
echo "USAGE: $0 --path <path_to_dir> [--confirm]"
}
if [ $# -lt 2 ]; then
usage
exit 1
fi
CONFIRM='no'
while [ $# -gt 0 ]; do
COMMAND=$1
case $COMMAND in
--path)
DIRECTORY=$2
shift 2
;;
--confirm)
CONFIRM='yes'
shift
;;
*)
break
;;
esac
done
if [[ ! -d $DIRECTORY ]]; then
echo "Directory ${DIRECTORY} does not exists."
usage
exit 1
fi
set -euo pipefail
GREEN="\e[1;32m"
RESET="\e[0m"
echo "The cleaning process has started, it may take a few minutes."
echo ""
pushd $DIRECTORY >/dev/null 2>&1
exec 5>&1
folders=()
IFS=$'\n'
for dir in $(find . -type d 2>/dev/null | grep 'obj$\|bin$'); do
FILESIZE=$(du "$dir" -s -h | tee /dev/fd/5)
FILENAME=$(echo $FILESIZE | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}')
folders+=($FILENAME)
done
echo ""
for value in ${folders[@]}; do
if [[ "$CONFIRM" == 'yes' ]]; then
printf "${GREEN}[${value}]${RESET} Would you like to remove it [Y/n]? "
read n
if [[ $n == 'q' ]]; then
break
fi
if [[ ! $n =~ [Yy] ]]; then
continue
fi
fi
rm -rf $value
printf "${GREEN}[${value}]${RESET} Removed.\n"
done
popd >/dev/null 2>&1