gunzip 目录中的所有 .gz 文件

The*_*Cat 30 gzip

我有一个包含大量.txt.gz文件的目录(其中名称不遵循特定模式。)

gunzip他们来说最简单的方法是什么?我想保留原来的名称,让他们从去whatevz.txt.gzwhatevz.txt

ger*_*ijk 52

仅此而已如何?

$ gunzip *.txt.gz
Run Code Online (Sandbox Code Playgroud)

gunzip将创建一个没有.gz后缀的 gunzipped 文件并默认删除原始文件(详情见下文)。*.txt.gz将由您的 shell 扩展到所有匹配的文件。

如果最后一点扩展到很长的文件列表,可能会给您带来麻烦。在这种情况下,请尝试使用find-exec为您完成工作。


从手册页gzip(1)

gunzip takes a list of files on its command line and  replaces  each  file
whose  name  ends  with  .gz, -gz, .z, -z, or _z (ignoring case) and which
begins with the correct magic number with an uncompressed file without the
original  extension.
Run Code Online (Sandbox Code Playgroud)

关于“原名”的注意事项

gzip 可以存储和恢复压缩时使用的文件名。即使您重命名压缩文件,您也会惊讶地发现它再次恢复为原始名称。

从 gzip 联机帮助页:

默认情况下,gzip 在压缩文件中保留原始文件名和时间戳。这些在使用-N选项解压缩文件时使用。当压缩文件名被截断或在文件传输后没有保留时间戳时,这很有用。

这些存储在元数据中的文件名也可以通过以下方式查看file

$ echo "foo" > myfile_orig
$ gzip myfile_orig 
$ mv myfile_orig.gz myfile_new.gz 
$ file myfile_new.gz 
myfile_new.gz: gzip compressed data, was "myfile_orig", last modified: Mon Aug  5 08:46:39 2019, from Unix
$ gunzip myfile_new.gz        # gunzip without -N
$ ls myfile_*
myfile_new

$ rm myfile_*
$ echo "foo" > myfile_orig
$ gzip myfile_orig
$ mv myfile_orig.gz myfile_new.gz 
# gunzip with -N
$ gunzip -N myfile_new.gz     # gunzip with -N
$ ls myfile_*
myfile_orig
Run Code Online (Sandbox Code Playgroud)


小智 7

使用此命令将当前目录下的所有文件进行 gunzip(解压 gz 文件)并保留原始文件:

gunzip -k *.gz
Run Code Online (Sandbox Code Playgroud)