【问题标题】:How do I create a tarball that only contains the files, and not a directory with the files?如何创建仅包含文件而不包含文件的目录的 tarball?
【发布时间】:2020-09-27 08:57:06
【问题描述】:

我有一个包含 3 个文件的文件夹 foo。 如何创建仅包含文件的 tarball。而不是 foo/ 与这三个文件。使用终端。
感谢您的帮助。

【问题讨论】:

    标签: terminal console tar


    【解决方案1】:

    使用 bash 和 GNU tar:

    shopt -s dotglob
    cd /path/to/foo && tar -cvf /tmp/file.tar -- *
    

    来自man bash

    dotglob:如果设置,bash 包含以 `.' 开头的文件名在路径名扩展的结果中。

    【讨论】:

    • 这适用于 bash,只要安装了它,我就可以去 bash 进行 tar 操作。你知道如何在 zsh 上设置类似的设置吗? shopt 在那里不起作用。
    • 这应该与 zsh 一起工作:setopt cshnullglob; cd /path/to/foo && tar -cvf /tmp/file.tar -- .* *
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-21
    • 2011-04-02
    • 1970-01-01
    • 2016-07-25
    • 2021-03-30
    • 1970-01-01
    相关资源
    最近更新 更多