How to delete many 0 byte files in linux?

small_ticket picture small_ticket · Jul 1, 2010 · Viewed 55k times · Source

I've a directory with many number of 0 byte files in it. I can't even see the files when I use the ls command. I'm using a small script to delete these files but sometimes that does not even delete these files. Here is the script:

i=100
while [ $i -le 999 ];do
    rm -f file${i}*;
    let i++;
done

Is there any other way to do this more quickly?

Answer

Didier Trosset picture Didier Trosset · Jul 1, 2010

Use find combined with xargs.

find . -name 'file*' -size 0 -print0 | xargs -0 rm

You avoid to start rm for every file.