-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspacehd
executable file
·76 lines (66 loc) · 1.81 KB
/
spacehd
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
#!/bin/bash
##############################################################################
#
# NAME: spacehd
#
# DESCRIPTION: Show a table of disk usage as reported by the df command.
# This script filters, formats and show totals of disk usage.
# It will only show filesystems mounted under /media, the home
# directory /home and the root /.
#
# USAGE: spacehd
#
# DEPENDENCIES: None
#
##############################################################################
#
df -P | awk '
BEGIN {
#
header = sprintf("%10s %9s %9s %9s %8s",
"Label", "Size", "Used", "Free", "%Used")
header_length = length(header)
# Create a line as long as the header
for (i = 0; i < header_length; i++) { line = line "-"; }
# Conversion factor from bytes to Gb (calculate once)
conv = 1024 * 1024
# Print header
print line
print header
print line
}
/^tmpfs/ {
next;
}
/\/media\/|\/home|\/$$/ {
# Aggregate measures
size += $2
used += $3
free += $4
# Figure out the name to show
# -----------------------------------------------------------------------
split($6, nameArr, /\//)
if (!nameArr[2]) {
name = "root";
}
else if (!nameArr[3]) {
name = "home";
}
else {
name = nameArr[3];
}
# -----------------------------------------------------------------------
printf("%10s %6d Gb %6d Gb %6d Gb %8s\n",
name, ($2/conv), ($3/conv), ($4/conv), $5)
}
END {
# Show totals in the footer
# -----------------------------------------------------------------------
print line
# This is a real percentage, unline the ones reported by df :/
pct = used * 100 / size
printf("%10s %6d Gb %6d Gb %6d Gb %7d%%\n",
"TOTAL", (size/conv), (used/conv), (free/conv), pct)
print line
}
'