【问题标题】:Tar files only in last directory listed in a path仅在路径中列出的最后一个目录中的 Tar 文件
【发布时间】:2022-06-17 20:51:15
【问题描述】:

我正在尝试编写一个 bash 脚本来压缩特定目录中的所有文件。

我在脚本中写了这个命令:

tar -cvf /opt/file/myFiles.tar.gz /opt/data/name/logs/

所以基本上我想在 /opt/file 中创建一个名为 myFiles.tar.gz 的 tar 文件,当我解压文件时,它应该给我文件夹日志和日志中的所有内容。

相反,我得到文件夹 opt 并且在到达日志文件夹之前我还必须检查数据和名称。

有没有办法让我在解压文件时只得到日志文件夹中的内容,而不必通过 opt/data/name?我也尝试过 /opt/data/name/logs/* 但它给出了相同的结果。

    标签: linux bash directory tar script


    【解决方案1】:

    GNU 和 BSD tar 有一个 -C 选项:

    tar -cv -f /opt/file/myFiles.tar.gz -C /opt/data/name/ logs/
    

    【讨论】:

      【解决方案2】:

      你可以试试这个吗?

      tar -cvf /opt/file/myFiles.tar.gz -C /opt/data/name/logs/ .
      

      【讨论】:

        猜你喜欢
        • 2013-08-02
        • 1970-01-01
        • 2013-03-17
        • 2018-05-22
        • 1970-01-01
        • 2011-12-26
        • 2011-02-11
        • 2011-03-18
        • 2019-01-02
        相关资源
        最近更新 更多