Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This command will find files of zero size:

find . -size 0

A filename returned might be

filename.001

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:

filename.txt
filename.bak
filename.ZZz
share|improve this question
add comment

1 Answer

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

explanation:

  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
add comment

Your Answer

 
discard

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.