bash 无需解压缩存档即可编辑文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/13633597/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Edit file without unzipping archive
提问by Satish
How do i edit file without unzipping archive, reason is i am writing automation task, I can do unzip, edit file and zip it, But it would be good if i can do it in runtime so it will save time to unzip/zip.
我如何在不解压缩存档的情况下编辑文件,原因是我正在编写自动化任务,我可以解压缩、编辑文件并将其压缩,但是如果我可以在运行时执行它会很好,这样可以节省解压缩/压缩的时间。
采纳答案by andrewdotn
The zipman pageprovides a -uoption to update a zip archive. You can use it like so:
该zip手册页提供了一个-u选项,以更新一个zip压缩文件。你可以像这样使用它:
zip -u bigzip.zip file/to/update1 file/to/update2 ...
It won't be instant, but it will be a lot faster. If I create a sample 200MB zip file:
它不会是即时的,但会快很多。如果我创建一个 200MB 的示例 zip 文件:
mkdir source
for (( f = 0; f < 200; f++ )); do
    head -c 1000000 /dev/random > source/${f}
done
zip -0r bigzip.zip source
then unzipping, editing one file, and rezipping takes about 9s on my machine:
然后在我的机器上解压缩、编辑一个文件并重新压缩大约需要 9 秒:
unzip bigzip.zip
head -c 1000000 /dev/random > source/3
zip -0r bigzip.zip source
but it takes only about 3s to call zip -u.
但调用 只需要大约 3 秒zip -u。
mkdir source
head -c1000000 /dev/random > source/3
zip -u bigzip.zip source/3

