-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdusage
More file actions
219 lines (211 loc) · 5.57 KB
/
dusage
File metadata and controls
219 lines (211 loc) · 5.57 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/sh
# Show disk usage in specified or current folder
# Usage: dusage -args -folder
# Static variables
RED='\033[0;31m'
NC='\033[0m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
# Functions:
sprint(){
echo ""
echo "It is ${YELLOW}highly recommended${NC} to you to use this program as ${CYAN}\"sudo\" or SuperUser${NC} in order to list and see all files in your folders. Anyway, this program perfectly runs without admin permissions"
echo ""
}
terms_of_service(){
echo "dusage Copyright (C) 2017 Javinator_9889"
echo " This program comes with ABSOLUTELY NO WARRANTY; for details click link below"
echo "This is free software, and you are welcome to redistribute it"
echo "under certain conditions."
echo "${CYAN}For more information, please click link below: ${NC}"
echo https://goo.gl/nAjgpH
}
help(){
echo "Usage: \"dusage [OPTIONAL](-r | --reverse; -d | --directory + PATH; -f | --file; -h | --help; -tos | --Terms)\""
echo "${RED}-r \t| --reverse: \t${NC}${YELLOW}show files in decreasing order"
echo "${RED}-d \t| --directory: \t${NC}${YELLOW}show used space in specified directory"
echo "${RED}-f \t| --file: \t${NC}${YELLOW}show used space by files, not only parent folder"
echo "${RED}-h \t| --help: \t${NC}${YELLOW}show help${NC}"
echo "${RED}-tos \t| --Terms: \t${NC}${YELLOW}show Terms of Service${NC}"
}
standard(){
sprint
echo "${CYAN}Showing space usage in: $PWD${NC}"
echo ""
echo "+------+-----------+"
echo "| Size | Directory |"
echo "+------+-----------+"
du -s -h -x * | sort -h
}
reverse(){
sprint
echo "${CYAN}Showing space usage in: $PWD${NC}"
echo ""
echo "+------+-----------+"
echo "| Size | Directory |"
echo "+------+-----------+"
if $is_file; then
find . -type f -exec du -s -h -x {} + | sort -hr
else
du -s -h -x * | sort -hr
fi
}
directory(){
sprint
echo "${CYAN}Showing space usage in: $cdirectory${NC}"
echo ""
echo "+------+-----------+"
echo "| Size | Directory |"
echo "+------+-----------+"
if $is_file && $is_rev; then
find "$cdirectory"* -type f -exec du -s -h -x {} + | sort -hr
elif $is_file; then
find "$cdirectory"* -type f -exec du -s -h -x {} + | sort -h
elif $is_rev; then
du -s -h "$cdirectory"* | sort -hr
else
du -s -h "$cdirectory"* | sort -h
fi
}
files(){
sprint
echo "${CYAN}Showing space usage in: $PWD${NC}"
echo ""
echo "+------+-----------+"
echo "| Size | Directory |"
echo "+------+-----------+"
if $is_rev; then
find . -type f -exec du -s -h -x {} + | sort -hr
else
find . -type f -exec du -s -h -x {} + | sort -h
fi
}
# Main
cdirectory=
is_rev=false
is_file=false
is_dir=false
case "$1" in
-d | --directory) shift
cdirectory=$1
shift
case "$1" in
-r | --reverse) shift
is_rev=true
case "$1" in
-f | --file) shift
is_file=true
directory
;;
"") directory
;;
*) echo "${RED}NON-ADMITTED OPTION${NC}"
;;
esac
;;
-f | --file) shift
is_file=true
case "$1" in
-r | --reverse) shift
is_rev=true
directory
;;
"") directory
;;
*) echo "${RED}NON-ADMITTED OPTION${NC}"
;;
esac
;;
"") directory
;;
*) echo "${RED}NON-ADMITTED OPTION${NC}"
;;
esac
;;
-r | --reverse) shift
is_rev=true
case "$1" in
-d | --directory) shift
is_dir=true
cdirectory=$1
shift
case "$1" in
-f | --file) shift
is_file=true
directory
;;
"") directory
;;
*) echo "${RED}NON-ADMITTED OPTION${NC}"
;;
esac
;;
-f | --file) shift
is_file=true
case "$1" in
-d | --directory) shift
is_dir=true
cdirectory=$1
directory
;;
"") reverse
;;
*) echo "${RED}NON-ADMITTED OPTION${NC}"
;;
esac
;;
"") reverse
;;
*) echo "${RED}NON-ADMITTED OPTION${NC}"
;;
esac
;;
-f | --files) shift
is_file=true
case "$1" in
-r | --reverse) shift
is_rev=true
case "$1" in
-d | --directory) shift
is_dir=true
cdirectory=$1
directory
;;
"") files
;;
*) echo "${RED}NON-ADMITTED OPTION${NC}"
;;
esac
;;
-d | --directory) shift
is_dir=true
cdirectory=$1
shift
case "$1" in
-r | --reverse) shift
is_rev=true
directory
;;
"") directory
;;
*) echo "${RED}NON-ADMITTED OPTION${NC}"
;;
esac
;;
"") files
;;
*) echo "${RED}NON-ADMITTED OPTION${NC}"
;;
esac
;;
-h | --help) shift
help
;;
-tos | --Terms) terms_of_service
;;
"") standard
;;
*) echo "Type ${CYAN} \"dusage -h\"${NC} in order to get help and see how this program works"
;;
esac