Zip命令不包括压缩dir本身 [英] Zip command without including the compressed dir itself

查看:151
本文介绍了Zip命令不包括压缩dir本身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设结构:

  / foo / bar / 
--file1
--file2
--file3
--folder1
--file4
--folder2
--file5

我要运行unix zip 实用程序,从 foo 文件夹压缩 bar 文件夹及其所有文件和子文件夹,但是在zip中没有 bar 文件夹,只使用命令行。



如果我尝试使用 -j 参数,它不会在zip中创建bar文件夹,但不创建 folder1 folder2 -rj 不起作用。



(我知道我可以输入bar, c> zip -r bar.zip。我想知道是否可以实现$ / foo / bar / zip -r bar.zip。

zip没有一个-C(更改目录)命令,如下所示:



可以:

  cd folder1&& ; zip -r ../bar.zip * 

从命令行shell



或者您可以使用bsdtar,它是来自libarchive的可以创建zip的tar版本。



bsdtar cf bar.zip --format zip -C folder1。



(这会创建一个名为./的文件夹 - 不确定该文件夹)


Suppose the structure:

/foo/bar/
        --file1
        --file2
        --file3
        --folder1
          --file4
        --folder2
          --file5

I want to run the unix zip utility, compressing the bar folder and all of it's files and subfolders, from foo folder, but not have the bar folder inside the zip, using only command line.

If I try to use the -j argument, it doesn't create the bar folder inside the zip as I want, but doesn't create folder1 and folder2. Doing -rj doesn't work.

(I know I can enter inside bar and do zip -r bar.zip . I want to know if it's possible to accomplish what $/foo/bar/ zip -r bar.zip . but doing it from $/foo).

解决方案

zip doesn't have a -C (change directory) command like tar does

you can do:

cd folder1 && zip -r ../bar.zip *

from within a command line shell

or you can use bsdtar which is a version of tar from libarchive that can create zips

bsdtar cf bar.zip --format zip -C folder1 .

(this creates a folder called ./ -- not sure a way around that)

这篇关于Zip命令不包括压缩dir本身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆