1

假设我们有一个 zip 文件,其中包含一个名为的目录aq,并且在当前工作目录中我们有文件:

./
|- aq/a.txt
|- b.txt

当我使用此命令时: 文件将被压缩到zip test.zip aq/*zip文件内的目录中a.txtaq

问题是我如何才能添加b.txt到文件aq内的目录中,而不像我对?test.zipb.txtaqa.txt

4

1 回答 1

0

Make a temp directory called, e.g. /tmp/$$/aq/, symlink into the temp directory and then do:

(cd /tmp/$$ && zip -r $ZIPDEST aq/)

i.e. zip using the temp dir. zip by default follows symbolic links, so it puts the file into the zip without making a copy.

This is pretty much how I construct complicated hierarchical zip files without copying everything to make the archive.

Tar has better options for renaming items as you're putting them into the archive, but you asked about zip.

于 2013-04-13T19:22:09.937 回答