将tar.gz转换为zip [英] Convert tar.gz to zip
本文介绍了将tar.gz转换为zip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Ubuntu网络服务器上有大量压缩的存档,我需要将它们转换为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?
推荐答案
我会使用bash(1)
单层纸:
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
它不是很漂亮,因为我不擅长bash(1)
.请注意,这会破坏很多目录,因此请确保在执行此操作之前了解它的作用.
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.
有关bash(1)
参考卡的详细信息,请参见 bash(1)
参考卡. ${foo%bar}
语法.
See the bash(1)
reference card for more details on the ${foo%bar}
syntax.
这篇关于将tar.gz转换为zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文