我已经花费了一点@ " 那个男人" 解决方案
切换到控制台,请按ctrl+x ,ctrl+e,粘贴在那里( cat <
#!/bin/bash
if [ $# -lt 3 ]; then
echo my_zip.zip your/existing/file_to_add.xml directory_in_zip/file_to_add.xml
exit
fi
python -c '
import zipfile as zf, sys
z=zf.ZipFile(sys.argv[1], "a")
z.write(sys.argv[2], sys.argv[3])
z.close()' $1 $2 $3
EOF
) > /tmp/zip-extend && chmod +x /tmp/zip-extend
然后运行 /tmp/zip-extend my_zip.zip your/existing/file_to_add.xml directory_in_zip/file_to_add.xml
例如:cd /tmp
touch first_file.txt
zip my_zip.zip first_file.txt
unzip -l my_zip.zip
mkdir -p your/existing
touch your/existing/file_to_add.xml
/tmp/zip-extend my_zip.zip your/existing/file_to_add.xml directory_in_zip/file_to_add.xml
unzip -l my_zip.zip
cd -
分析结果:Archive: my_zip.zip
Length Date Time Name
--------- ---------- ----- ----
0 2013-12-17 15:24 first_file.txt
0 2013-12-17 15:24 directory_in_zip/file_to_add.xml
--------- -------
0 2 files