Shell script to remove empty files

Hi All,

Can anyone please write a shell script to remove the empty files using an if condition.

please help me out , urgent

thanks

find . -type f -size 0 -exec rm {} \;
1 Like

thank you so much !!!!!!

Put the below script in the directory in which you want to remove empty files (i.e. files with size zero)

#! /bin/bash
for x in *
do
    if [ -s $x ]
    then
        continue
    else
        rm -rf $x
    fi
done
1 Like

Thanks a lot !!!!!!

 find ~ -empty 

or

for i in *
do
if [ -s $i ]; then
echo "$i is a file and size is greater than zero."
else
echo "$i is an empty file and deleting now..."
rm -rf $i
fi
done
 
for i in *; do [ ! -s $i ] && rm -rf $i; done