2012-11-29 31 views
2

如何在不解壓縮的情況下編輯文件,原因是我正在編寫自動化任務,我可以解壓縮,編輯文件並將其壓縮,但如果我可以在運行時執行它,將節省時間解壓縮。編輯文件時無需解壓縮存檔

+0

重複的問題。你不能這樣看下面:http://stackoverflow.com/questions/6334037/how-to-change-a-file-inside-an-archive-ear-file-without-extracting-entire-fil –

回答

2

zip man page提供了一個-u選項來更新zip壓縮文件。您可以使用它像這樣:

zip -u bigzip.zip file/to/update1 file/to/update2 ... 

這不會是即時的,但它會快很多。如果我創建一個樣本200MB的zip文件:

mkdir source 
for ((f = 0; f < 200; f++)); do 
    head -c 1000000 /dev/random > source/${f} 
done 
zip -0r bigzip.zip source 

然後解壓,編輯一個文件,並重新拉上大約需要我的機器上787-9:

unzip bigzip.zip 
head -c 1000000 /dev/random > source/3 
zip -0r bigzip.zip source 

但是隻需要3秒左右叫zip -u

mkdir source 
head -c1000000 /dev/random > source/3 
zip -u bigzip.zip source/3