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.

I'm hoping you can lend me your expertise.

I use shared hosting on Hostgator and need to figure out how to delete all .gz files in multiple directories every hour. I think I have the cronjob command correct to do this for one directory:

/usr/bin/find /path/to/directory/ -type f -name '*.gz' -exec rm {} \;

Is that correct?

If so, how would I perform the same action, but for multiple (i.e. dozens) directories? I'm guessing I can execute one script instead of a bunch of individual cronjob but I'm new to this. What would such a script look like? And how would I execute the script via a cronjob?

Thanks in advance for any assistance!

share|improve this question
    
If your version of find supports it, you might want to use -delete instead of -exec rm {} \; or at least + instead of \;. –  Dennis Williamson Feb 23 '11 at 17:33
    
An alternative is /usr/bin/find /path/to/directory/ -type f -name '*.gz' -print0 | xargs -0 rm which avoids executing rm over and over for each single file. –  hlovdal Feb 23 '11 at 23:14

1 Answer 1

up vote 1 down vote accepted

Pass multiple paths to find.

find /dir1 /dir2 ...
share|improve this answer
    
Thanks! And that will work for a large number of directories? –  Glen Feb 23 '11 at 17:31
    
It should, although I don't know the exact maximum. –  Ignacio Vazquez-Abrams Feb 23 '11 at 17:36

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.