Last active
December 23, 2015 10:59
-
-
Save starlightsys/6625600 to your computer and use it in GitHub Desktop.
A shell script that generates a simple report of hard drive usage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
CURRENT_DATETIME=`date "+%Y%m%d_%H%M%S_%z" | sed -e "s/+//"` | |
REPORTFILE="${CURRENT_DATETIME}_storage_report.txt" | |
echo "Generating file ${REPORTFILE} ..." | |
echo "Storage report for `date "+%Y-%m-%d %H:%M:%S %z"`" > ${REPORTFILE} | |
echo "========================================================================" >> ${REPORTFILE} | |
# If you have sort version 8.17 or newer, use the following code: | |
find . -mindepth 1 -maxdepth 1 -print0 | xargs -0 du -hs | sort -hr >> ${REPORTFILE} | |
# If you have an older version of sort, use this code instead: | |
# (find . -mindepth 1 -maxdepth 1 -print0 | xargs -0 du -sk) | sort -n | perl -ne '($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}' | tac >> ${REPORTFILE} | |
echo "Complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment