small_ticket small_ticket - 11 months ago 45
Linux Question

How to delete many 0 byte files in linux?

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:

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

Is there any other way to do this more quickly?


Use find combined with xargs.

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

You avoid to start rm for every file.