假设我们有一个 zip 文件,其中包含一个名为的目录aq
,并且在当前工作目录中我们有文件:
./
|- aq/a.txt
|- b.txt
当我使用此命令时:
文件将被压缩到zip test.zip aq/*
zip文件内的目录中a.txt
aq
问题是我如何才能添加b.txt
到文件aq
内的目录中,而不像我对?test.zip
b.txt
aq
a.txt
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.