linux-server-tools/dirsize/dirsize.sh

24 lines
509 B
Bash
Raw Normal View History

2023-10-27 10:53:45 +02:00
#!/bin/bash
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