-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdiskhogs.sh
executable file
·33 lines (29 loc) · 999 Bytes
/
diskhogs.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
# +----+----+----+----+
# | | | | |
# Author: Mark David Scott Cunningham | M | D | S | C |
# +----+----+----+----+
# Created: 2014-07-12
# Updated: 2016-09-26
#
#
#!/bin/bash
getusr(){ pwd | sed 's:^/chroot::' | cut -d/ -f3; }
dash(){ for ((i=1;i<=$1;i++)); do printf "-"; done; }
if [[ "$@" =~ "-h" ]]; then
echo -e "\n Usage: diskhogs [maxdepth] [-d]\n";
return 0;
fi;
if [[ $@ =~ [0-9]{1,} ]]; then
DEPTH=$(echo $@ | grep -Eo '[0-9]{1,}');
else
DEPTH=3;
fi;
echo -e "\n---------- Large Directories $(dash 51)";
du -h --max-depth $DEPTH $PWD | grep -E '[0-9]G|[0-9]{3}M';
if [[ ! $@ =~ '-d' ]]; then
echo -e "\n---------- Large Files $(dash 57)";
find $PWD -type f -size +100000k -group $(getusr) -exec ls -lah {} \;;
fi;
echo -e "\n---------- Large Databases $(dash 53)";
du -sh /var/lib/mysql/$(getusr | cut -c1-8)_* | grep -E '[0-9]G|[0-9]{3}M';
echo