gzip all files with specific extensions

I would use

find /path/to/dir \( -name '*.css' -o -name '*.html' \) -exec gzip --verbose --keep {} \;

Change name to iname if you want to match the extensions case-insensitively (i.e. include .CSS and/or .HTML extensions). You can omit the /path/to/dir if you want to start the recursive search from the current directory.


you can do that with a for loop to find every file then compress it:

for i in `find | grep -E "\.css$|\.html$"`; do gzip "$i" ; done

To get the list of files:

find -type f | grep -P '\.js|\.html|\.css'

And to gzip all those files:

find -type f | grep -P '\.js|\.html|\.css' | tar cvzf archive.gz -T -

Tags:

Gzip