Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This command will find files of zero size:

find . -size 0

A filename returned might be


I am looking for a one liner that will delete files found with this, plus any that have the same filename with a different extension (which would be non-zero sized), so these files would be deleted too:

share|improve this question
up vote 6 down vote accepted
$> find . -size 0 | while read f; do rm "${f%.*}."* ; done


  1. find all files with size 0
  2. pipe the names to the while loop
  3. cut of the suffix (extension) part ${f%.*} (read man bash)
  4. rm all other files with the same base
share|improve this answer
Great, I was trying to get the suffix cutting working in -exec with find but this way is easier. – Paul Dec 2 '11 at 8:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.