如何在没有根目录的情况下将文件和目录添加到 zip 文件中?
zip 实用程序在此目录结构上作为 zip -r out.zip base/*
调用时
.
./base
./base/b
./base/b/c
./base/d
会创建以下结果
adding: base/b/ (stored 0%)
adding: base/b/c (stored 0%)
adding: base/d (stored 0%)
我想从以下输出中获取包含数据的文件,
adding: b/ (stored 0%)
adding: b/c (stored 0%)
adding: d (stored 0%)
我希望 - j 选项对我有帮助,但它没有:它完全扁平化了目录结构。 目前,我找到的唯一解决方案是 cd 到 base 并从这里调用 zip,但我想知道是否有一个电源开关我在文档中无法识别。
The zip utility program, when invoked as zip -r out.zip base/*
on this directory structure
.
./base
./base/b
./base/b/c
./base/d
creates the following result
adding: base/b/ (stored 0%)
adding: base/b/c (stored 0%)
adding: base/d (stored 0%)
I would like to obtain a file containing data as from the following output
adding: b/ (stored 0%)
adding: b/c (stored 0%)
adding: d (stored 0%)
I expected the -j option to help me, but it does not: it completely flattens the directory structure. At the moment, the only solution I found is to cd into base and invoke zip from here, but I was wondering if there's a powerswitch I fail to recognize as such in the docs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道您不想 cd ,但是...
如果所有其他方法都失败并且您希望将对 zip 的调用保留到一行,您可以链接调用并使用相对路径在根目录中输出 zip:
对于 Windows:
cd base & zip -r ..\out.zip * & cd ..
对于 Linux/Unix:
cd base ; zip -r ../out.zip * ; cd ..
I understand that you do not want to
cd
, but...If all else fails and you are hoping to keep your call to zip down to one line, you could chain the calls and use a relative path to output zip in the root:
For Windows:
cd base & zip -r ..\out.zip * & cd ..
For Linux/Unix:
cd base ; zip -r ../out.zip * ; cd ..