-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-files-size.sh
executable file
·47 lines (39 loc) · 1.2 KB
/
get-files-size.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
#!/bin/bash
#du -h --max-depth=1|grep "\<[1-9]\{1,\}G"
if [ -n "${1}" ]; then
CURRENT_USER=${1}
elif [ -n "${USER}" ]; then
CURRENT_USER=${USER}
else
echo "Unknown user."
fi
TEMP_FILE=/tmp/${CURRENT_USER}_temp.txt
# Get the size of each directory
# -d is not supported with old version of du
# du -d 1 -h > ${TEMP_FILE}
if [ "`uname -s`" = "Darwin" ]; then
du -d 1 -h > ${TEMP_FILE}
ls -alhrS | grep -v -e "^d" | awk '{print $5 "\t" $9}' >> ${TEMP_FILE}
else
du --max-depth 1 -h > ${TEMP_FILE}
fi
# Add the tailing / to each item
sed -i -e 's/$/&\//g' ${TEMP_FILE}
# Get the size of each file, excluding directories
#ls -ahlS -1 -F | grep -v "/$" | awk '{print $5" \t./" $(9)}' >> ${TEMP_FILE}
ls -alhS -1 -F | grep -v "/$" | awk '{
printf $5"\t./"$9;
if (NF > 9)
{
for(i=10; i<=NF; i++)
{
printf " "$i
}
}
printf "\n"
}' >> ${TEMP_FILE}
echo Listing by size
for unit in T G M K; do
cat ${TEMP_FILE} | grep -e "[0-9]${unit}"|sort -nr -k 1
done
rm ${TEMP_FILE}