Franz Kafka Franz Kafka - 1 year ago 119
Linux Question

Linux delete file with size 0

How do I delete a certain file in linux if its size is 0. I want to execute this in an crontab without any extra script.

l filename.file | grep 5th-tab | not eq 0 | rm

Something like this?

Answer Source

This will delete all the files in a directory (and below) that are size zero.

find /tmp -size  0 -print0 |xargs -0 rm

If you just want a particular file;

if [ ! -s /tmp/foo ] ; then
  rm /tmp/foo
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download