Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert tar.gz to zip

I've got a large collection of gzipped archives on my Ubuntu webserver, and I need them converted to zips. I figure this would be done with a script, but what language should I use, and how would I go about unzipping and rezipping files?

like image 911
Dan Avatar asked Jun 10 '11 04:06

Dan


People also ask

Can 7-Zip unzip Tar GZ?

gz File by 7-Zip. Go to your . tar. gz file location, right-click on it, and choose Extract files option.


1 Answers

I'd do it with a bash(1) one-liner:

for f in *.tar.gz;\
do rm -rf ${f%.tar.gz} ;\
mkdir ${f%.tar.gz} ;\
tar -C ${f%.tar.gz} zxvf $f ;\
zip -r ${f%.tar.gz} $f.zip ;\
rm -rf ${f%.tar.gz} ;\
done

It isn't very pretty because I'm not great at bash(1). Note that this destroys a lot of directories so be sure you know what this does before doing it.

See the bash(1) reference card for more details on the ${foo%bar} syntax.

like image 115
sarnold Avatar answered Sep 18 '22 13:09

sarnold