Last active
October 17, 2016 10:44
-
-
Save swasher/7879ae648ed4aece7e96 to your computer and use it in GitHub Desktop.
del_empty
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/bash | |
# This script analyze directories in current directory, | |
# and delete all directories that smaller than "bytes" bytes | |
####### SETUP ############ | |
# Max bytes for "empty" folder | |
bytes=1500000 | |
##### END SETUP ########## | |
old_IFS="$IFS" | |
IFS=' | |
' | |
strVar=`du -b --max-depth=1 --bytes | awk -F"\t" '{if ($1 < BYTES) print substr($2, 3, length($2))}' BYTES=$bytes | sort` | |
echo -e "\n" | |
if [ -z "$strVar" ]; then | |
echo "Нет пустых директорий" | |
exit 0 | |
else | |
for line in $strVar; do | |
echo $line | |
done | |
fi | |
echo -e "\n" | |
read -p "Are you sureto remove it? y/n " -n 1 -r | |
if [[ $REPLY =~ [Yy] ]]; | |
then | |
echo -e "\n" | |
for line in $strVar; do | |
echo "Removed $line"; | |
rm -r "$line"; | |
done | |
else | |
echo -e "\n"Cancel by user | |
fi | |
echo -e "\n" | |
IFS=$old_IFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment