【问题标题】:gzip on a folder without changing the file extensiongzip 在文件夹上而不更改文件扩展名
【发布时间】:2013-09-10 05:04:39
【问题描述】:

所以我使用亚马逊来提供一些文件。

我想在上传这些文件之前对其进行 gzip 压缩

首先我将模板复制到一个新文件夹中

cp -r templates/ templatesGZIP

然后我 GZIP 那个文件夹

gzip -r templatesGZIP

问题在于这会将 .gz 添加到所有文件名中。例如 homeTemplate.html 更改为 homeTemplate.html.gz

在运行 gzip -r templatesGZIP 时有什么方法我声明我想保持扩展相同

谢谢

【问题讨论】:

    标签: linux gzip


    【解决方案1】:

    Bash script: Gzip an entire folder and keep files extensions same

    这肯定有助于先用 gzip 压缩它们,然后重命名它们。

    感谢和问候,
    阿洛克

    【讨论】:

      【解决方案2】:

      gzip 只做一件事,将单个文件转换为 gz 存档。您需要的是一个 tar.gz 文件。你的朋友是tar,也可以使用gzip

      cp -r templates templatesGZIP
      tar czf templatesGZIP.tar.gz templatesGZIP
      

      背景:tar 还做得很好:它将目录结构转换为单个文件。上面的tar 命令解释:

      • c = 创建
      • z = 压缩,默认 gzip
      • f FILE = 存档文件的名称

      【讨论】:

        【解决方案3】:

        复制目录后

        find templatesGZIP -type f ! -wholename *images* -exec gzip {} \; -exec mv {}.gz {} \;
        

        【讨论】:

          【解决方案4】:

          您可以使用stdout 作为临时缓冲区并将输出写入您选择的文件中:

          gzip -cr templatesGZIP > outputfile.extension
          

          【讨论】:

            【解决方案5】:

            gzip 中没有执行此操作的选项。使用双目录方法,以下应该可以解决问题

            for in_file in $(find templates -type f)
            do
                out_file="templatesGZIP/${in_file#templates/}"
                mkdir -p "$(dirname "$out_file")"
                gzip -c <"$in_file" >"$out_file"
            done
            

            使用此方法,无需cp 命令。

            这已经过测试。

            对此有一条评论 - 很少看到没有扩展名的 gzip 文件。

            【讨论】:

              猜你喜欢
              • 2013-05-20
              • 1970-01-01
              • 2021-07-22
              • 2012-12-30
              • 1970-01-01
              • 1970-01-01
              • 2013-07-12
              • 1970-01-01
              • 2017-03-12
              相关资源
              最近更新 更多