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

What can I replace with _____ to recursively gzip every file starting at myFolder and have the gzip be overwrite the file (rename the gzip file to the original filename)?

share|improve this question

migrated from Jul 31 '09 at 20:51

This question came from our site for professional and enthusiast programmers.

3 Answers 3


find myFolder -type f -exec gzip {} +
share|improve this answer
Be aware that this will rename your files from myFile to myFile.gz – Kristof Provost Jul 30 '09 at 10:42

A simple, not very elegant bash script is to simply cd in, gzip them all in a loop, and mv them back (gzip by default removes the non-compressed file):

cd myFolder
for f in `find ./ -type f`
    gzip $f
    mv $f.gz $f

Put that in a file called "" for example, chmod -775 and run it like ./ (if running from within myFolder itself, remove the "cd myFolder" line from the script).

share|improve this answer
And yes I do know backticks are evil, but as I said this is just a quick hack script. – Wesley Mason Jul 30 '09 at 10:50
why are backticks evil, what do you replace them with ? – Anonymous Jul 30 '09 at 13:36
See – Wesley Mason Jul 31 '09 at 10:13

You could also try

 find myFolder -type f -exec gzip {} \; -exec mv {}.gz {} \;
share|improve this answer
Aha, forgot about multiple -exec calls in find, me likey – Wesley Mason Jul 31 '09 at 11:09

Your Answer


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