Home » Questions » Computers [ Ask a new question ]

Linux Command line: recursively overwriting every file with a gzipped version?

Linux Command line: recursively overwriting every file with a gzipped version?

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)?

Asked by: Guest | Views: 162
Total answers/comments: 1
Guest [Entry]

"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):

#!/bin/bash
cd myFolder
for f in `find ./ -type f`
do
gzip $f
mv $f.gz $f
done

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