Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script: Gzip an entire folder and keep files extensions same [closed]

Tags:

bash

gzip

I want to gzip every file in a folder recursively and keep the original name and extension after compression.

I have tried sudo gzip -9 -r folder however now each file has an .gz extension added to the original such as 2852b65c1d8b.css.gz while I want to keep the name as 2852b65c1d8b.css for the gzipped file to upload to Amazon S3.

like image 927
Hellnar Avatar asked Feb 20 '26 03:02

Hellnar


1 Answers

Using this does what you want:

find folder -type f -exec gzip -9 {} \; -exec mv {}.gz {} \;

The 1st exec gzip the files, the 2nd rename them.

like image 163
jfg956 Avatar answered Feb 22 '26 02:02

jfg956



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!