Simple script with nice formatting.
The results show:
df -m
)Directory sizes are recursively calculated (the totals include subdirectories).
In line 6, the grep -Po
command allows us to use Perl-like regex syntax (e.g. lookaheads are supported), and to only return the matched portion of the searched text.
The script:
|
|
Output is formatted. For example, running the script against a Maven repo gives a directory size listing like this:
149,731,531 - .
109,943,053 - ./.m2
109,943,029 - ./.m2/repository
77,870,516 - ./.m2/repository/org
38,947,091 - ./.ivy2
38,947,072 - ./.ivy2/cache
10,494,306 - ./.m2/repository/com/google
8,723,165 - ./.m2/repository/org/apache/maven
8,471,569 - ./.m2/repository/org/hibernate
The directory sizes are right-justified using %15
and the thousand separators are added using \'
(line 28).