-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrmvoiddirs
More file actions
executable file
·48 lines (43 loc) · 870 Bytes
/
rmvoiddirs
File metadata and controls
executable file
·48 lines (43 loc) · 870 Bytes
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
#! /bin/bash
recursive_rm(){
local dir="$1"
if [ "$dir" != "." -a "$(ls -A "$dir")" == "" ]; then
rmdir "$dir"
[ "${dir%/*}" != "$dir" ] && recursive_rm "${dir%/*}"
echo mkdir \""$(echo "$start_path$dir" | sed 's/"/\\"/g;s/\$/\\\$/g')"\"
fi
}
cycle(){
if [ "$1" == "" ]; then
start_path=
else
start_path="${1%/}/"
cd "$start_path"
[ $? != 0 ] && exit 1
fi
dir=
after_dir=0
while read line ; do
if [ $after_dir == 1 ]; then
if [ "$line" == "" ]; then
recursive_rm "$dir"
fi
after_dir=0
fi
if [ "${line#./}" != "$line" ]; then
dir="${line%:}"
after_dir=1
fi
done < <(ls -ALR)
if [ $after_dir == 1 ]; then
recursive_rm "$dir"
fi
if [ "$1" != "" ]; then
cd - >/dev/null
if [ "$(ls -A "$start_path")" == "" ]; then
rmdir "$start_path"
echo mkdir \""$(echo "$start_path" | sed 's/"/\\"/g;s/\$/\\\$/g')"\"
fi
fi
}
cycle "$1" | sort