delete zero byte file

Hello

I have a requirement where i need to find the zero byte size file in the directory and need to delete that zero byte file.

Thanks

try this

 find /dir -type f -size 0 -print -exec rm '{}' \;

before running the above command that will delete the 0 size files, make sure it gives the desired files first.

find /dir -type f -size 0 -print

cheers,
Devaraj Takhellambam

for f in *
do
  [ -s "$f" ] && continue   ## file exists, but is not empty
  [ -f "$f" ] && rm "$f"
done
1 Like