代码之家  ›  专栏  ›  技术社区  ›  Somebody still uses you MS-DOS

Zip命令,但不包括压缩的目录本身

  •  5
  • Somebody still uses you MS-DOS  · 技术社区  · 16 年前

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

    我想运行unix zip 实用程序,压缩 bar 文件夹及其所有文件和子文件夹,从 foo 文件夹,但没有

    如果我尝试使用 -j 参数,它不会像我所希望的那样在zip中创建bar文件夹,但不会创建 folder1 folder2 . 做 -rj 不起作用。

    zip -r bar.zip . 我想知道是否有可能完成$/foo/bar/ 邮编-r条形图.zip. 但从$/foo开始)。

    3 回复  |  直到 16 年前
        1
  •  6
  •   Mark Harviston    5 年前

    zip不像tar那样有-C(更改目录)命令

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

    或者可以使用bsdtar,它是libarchive的tar版本,可以创建zips

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

    (这将创建一个名为./--的文件夹,但不确定如何解决此问题)

        2
  •  8
  •   ryenus    9 年前

    你必须这么做 cd /foo/bar 然后 zip -r bar.zip .

    # instead of: cd /foo/bar; zip -r bar.zip; cd -
    
    ( cd /foo/bar; zip -r bar.zip . )
    

    封闭的(paren-grouped)命令在子shell中运行,其中的cd不会影响外壳会话。

    看到了吗 sh manual

    Compound Commands
        A compound command is one of the following:
    
        (list) list is executed in a subshell environment (see COMMAND EXECUTION ENVIRONMENT below).  
               Variable assignments and builtin commands that affect the shell's environment do not remain in effect after the command completes.  
               The return status is the exit status of list.
    
        3
  •  2
  •   agf    15 年前

    我不能支持警察的推理。我也在寻找这个解决方案。

    .ods 通过构建内部xml文件并将它们压缩到一起。它们必须在存档的根目录中,否则在尝试运行OOo时会出错。

    我相信还有很多其他方法可以做到这一点: OOo中的文件名为 blank.ods blank ,然后尝试运行:

    cd blank && zip -r ../blank.ods *
    

    按照我编写的方式,shell在一个命令后关闭,因此如果您只需添加 && cd .. 到命令行:

    cd blank && zip -r ../blank.ods * && cd ..