linux-server-tools/dirsize/dirsize.sh

47 lines
1.4 KiB
Bash

#!/bin/bash
## MakeVHost Script
## Author: Ze'ev Schurmann
## Reddit: u/thisiszeev
## License: GPL-3.0 or later
## Copy this file to /usr/bin as dirsize (not dirsize.sh)
## From any folder that you want to assess the size of each folder within the current folder,
## simply type dirsize
## Please consider making me small donation. Even though my scripts are open source and free to use, I still need to eat. And the
## occasional bottle of wine also goes down well.
## $5 buys me a cup of coffee
## $10 buys me a nice burger
## $20 buys me a bottle of wine
## Anything above that will be awesome as well.
## You can send me a donation via Paypal https://www.paypal.com/paypalme/thisiszeev
## Drop me a message on Reddit if you do make a donation.
## Support is only offered freely to those who donate $20 or more.
## Your donation contributes to further development.
## If you need a custom script, contact me on Reddit for pricing.
if [[ -f "/tmp/dir.list" ]]; then
rm "/tmp/dir.list"
fi
if [[ -f "/tmp/dir.list" ]]; then
echo "Couldn't delete the temp file from a previous run."
echo "As root please run..."
echo
echo "# rm /tmp/dir.list"
echo
echo "or use sudo..."
echo
echo "$ sudo rm /temp/dir.list"
echo
exit 1
fi
find . -maxdepth 1 -type d > "/tmp/dir.list"
while read -r foldername; do
if [[ $foldername != "." ]]; then
du -h $foldername | tail -1
fi
done < "/tmp/dir.list"
rm "/tmp/dir.list"