Script to remove all empty files within the directory structure?

Hi I need to write a shell script which basically searches for all the empty files within the directory structure, lists them before asking the user to confirm if they would like to delete them. If the user deletes the file then a notice would appear confirming the file is deleted.

I've be trying to do this for weeks now and its driving me mad, I'm quite new to this, although I am getting to grips with it slowly.

Cheers

use the following command to identify the empty files in ur directory

find . -name "*.*" -size 0c

Thanks for the reply m8.

I don't think I explained what I was trying to do correctly, I'm trying to create a shell script that will allow me to find all empty files within my directory tree, list them and then give me the option of deleting them. I would like to be able to get the option of deleting them in the format of :

delete word.doc y/n? :> y
word.doc deleted.

I know some files that are empty are not to be deleted this is why I need to see what I am about to get rid of.

I'm just strating out doing Linux and I've hit a brick wall with this so any help would be appreciated, cheers.

This pseudo code may put you on right lines...

file_names=`find . -name "*.*" -size 0c`
for i in $file_names
do
print "Do you want to delete the file?"
read input
if ans='y' or 'Y'
rm -f $i
else 
#do nothing
echo "File not deleted"
fi
done

You can also use

find . -name "*.*" -size 0c -exec rm -i {} \;

"rm -i" asks you if you want to delete it or not. Works on Debian Linux and AIX at least.

Btw. that find did not work for me on Debian and AIX. If you encounter the same problem, you might try:

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

cheers guys for the help, im gonna give it a go and I'll let you's know how I do.

Cheers