Script to delete all empty files in a directory. This was specially designed for directories that have hundreds of thousands of files in them (ls has a limitation for directories with a large number of files in them, so find must be used)
#!/bin/bash
# Example: ./delete_empty_files.sh /home/random_files/
usage()
{
echo "Usage: $0 Directory_Name"
exit 1;
}
test -d "$1" || usage
function test_and_delete()
{
while read line1; do
size=`stat -c %s $line1`
if [ $size -lt 1 ]; then
#echo "$line1 is $size ( This one is empty ) "
rm -f $line1
else
#echo "$line1 is $size "
fi
done
}
cd $1
find -name "*" | test_and_delete
0 comments:
Post a Comment