【问题标题】:How do I create a tar archive that will not expand to a subfolder?如何创建不会扩展到子文件夹的 tar 存档?
【发布时间】:2013-08-14 22:27:41
【问题描述】:

我不想创建没有内部目录结构的“平面”压缩包。但我希望顶级文件是“松散的”,而不是镜像它们最初所在的目录结构。

考虑:

+ archives
|
+ data
    |
    + site
        |
        + file1.html
        |
        + subdirectory
               |
               + etc...

如果我 cd 进入 archives 并在那里创建我的 tar,例如:tar -czf archive.tgz ../data/site/* 当我稍后提取 tarball 时,它将重新创建 data/site/...,然后我将不得不 mv data/site/* ../some/other/dir

我希望能够只使用tar -xzf archive.tgz -C ../some/other/dir 并在../some/other/dir 中包含例如file1.html。

【问题讨论】:

    标签: unix tar directory-structure archive-tar


    【解决方案1】:

    而不是cding 到archives 并在那里运行tar 并带有指向tarfile 内容的路径,您应该cd 到内容所在的位置并指定您正在创建的tarfile 的路径:

    cd data/site
    tar -czf ../../archives/archive.tgz *
    

    【讨论】:

      【解决方案2】:

      您也可以使用选项tar -czf archive.tgz --directory=data/site/ . 而无需进入文件夹

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-10
        • 1970-01-01
        • 2017-04-29
        • 2016-04-11
        • 2017-09-19
        • 1970-01-01
        相关资源
        最近更新 更多