如何在没有根目录的情况下将文件和目录添加到 zip 文件中?

发布于 2024-07-24 09:17:46 字数 492 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凌乱心跳 2024-07-31 09:17:46

我知道您不想 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 ..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文