简体   繁体   English

将文件添加到zip文件中的特定目录

[英]add files to a specafic directory inside zip file

Let's say we have a zip file contains a directory named aq and in the current working directory we have files: 假设我们有一个包含名为aq的目录的zip文件,并且在当前工作目录中有以下文件:

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

When i use this command: zip test.zip aq/* the a.txt file will be zipped into the aq directory that's inside the zip file 当我使用以下命令时: zip test.zip aq/* a.txt文件将被压缩到zip文件内部的aq目录中

The question is how then can I add b.txt into the aq directory that's inside the test.zip file without putting the b.txt in the aq directory first which is in the current working directory like what I did with the a.txt ? 问题是,然后我如何才能将b.txt添加到test.zip文件内的aq目录中,而不将b.txt首先放在当前工作目录中的aq目录中,就像我对a.txt所做的那样?

Make a temp directory called, eg /tmp/$$/aq/ , symlink into the temp directory and then do: 将一个临时目录(例如/tmp/$$/aq/ )符号链接到该临时目录中,然后执行以下操作:

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

ie zip using the temp dir. 即使用临时目录压缩。 zip by default follows symbolic links, so it puts the file into the zip without making a copy. zip默认情况下跟随符号链接,因此它将文件放入zip中而不进行复制。

This is pretty much how I construct complicated hierarchical zip files without copying everything to make the archive. 这几乎就是我构造复杂的分层zip文件而不复制所有内容以创建存档的方式。

Tar has better options for renaming items as you're putting them into the archive, but you asked about zip. 当您将项目放入归档文件时,Tar有更好的重命名选项,但是您询问了zip。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM