gzip */*.txt

But the extension for each file will be .txt.gz, as gzip uses it to know the original filename.

Answer from Juliano on Stack Overflow
Discussions

command line - gunzip multiple files - Unix & Linux Stack Exchange
I have a directory where there are multiple folders, each of folder contains a .gz file. How can I unzip all of them at once? My data looks like this List of folders A B C D In every of them the... More on unix.stackexchange.com
🌐 unix.stackexchange.com
Compress more than 1 file on a Gzip files
Hello. I need to gzip various .xml files into only one compressed gzip file. Is there any way ? T.I.A. More on discuss.4d.com
🌐 discuss.4d.com
8
0
November 25, 2022
Multiple files in a gzip archive
Is it possible to create a single compressed archive that contains a number of text or csv files? It looks like gzip.jl only zips a single file at a time. Thanks! More on discourse.julialang.org
🌐 discourse.julialang.org
6
0
June 14, 2017
How to gzip Multiple Files into Unique Zipped Files in One Shot? - Software & Applications - Spiceworks Community
Hi Guys, If let’s say I have three files in one directory, A , B and C, I want to zip them to.gz as A.gz, B.gz and C.gz. Is there any command to do this in one shot, rather key in each command for each file? as I have more than 10 thousands files in the directory. Best Regards, Ken More on community.spiceworks.com
🌐 community.spiceworks.com
0
October 22, 2009
Top answer
1 of 2
17

Unlike ZIP, RAR or 7-Zip, for example, gzip can only compress one file. As you’ve already noted, there is the tar program which can serialize multiple files into one which makes them ready for gzip. The traditional Unix philosophy prefers to use multiple simpler and more specialized tools than one monolithic and complicated. In this case, it results in using tar and gzip consecutively, resulting in a .tar.gz (or .tgz) file.

However, GNU tar includes the -z option which compresses the result of the traditional tar using gzip in just one command.

.tar.gz files are mostly created using the -czvf options:

  • create a new archive
  • gzip (alternatives: j for bzip2, J for xz)
  • verbose (list processed files; optional)
  • output file (the following argument specifies the output file)

In your example, you can use the command:

tar -czvf test.tar.gz file.mp4 bar.txt

Is there any way to watch inner files without decompression with gzip or bzip2?

Yes, your command also works for a .tar.gz file:

tar -tvf test.tar.gz

Further reading

  • GNU TAR Manual page
  • 10 quick tar command examples to create/extract archives in Linux
2 of 2
4

gzip is a compressor, not an archiver, but it works well with tar

tar -cvzf file.tar.gz path-to-files-or-directories-to-compress

See man tar

Compression options
   -a, --auto-compress
          Use archive suffix to determine the compression program.

   -I, --use-compress-program=COMMAND
          Filter data through COMMAND.  It must accept the -d option,  for
          decompression.  The argument can contain command line options.

   -j, --bzip2
          Filter the archive through bzip2(1).

   -J, --xz
          Filter the archive through xz(1).

   --lzip Filter the archive through lzip(1).

   --lzma Filter the archive through lzma(1).

   --lzop Filter the archive through lzop(1).

   --no-auto-compress
          Do not use archive suffix to determine the compression program.

   -z, --gzip, --gunzip, --ungzip
          Filter the archive through gzip(1).

   -Z, --compress, --uncompress
          Filter the archive through compress(1).

And yes, you can watch compressed archives the same way.

🌐
Baeldung
baeldung.com › home › files › file compression › compression of multiple files individually with gzip
Compression of Multiple Files Individually With gzip | Baeldung on Linux
March 18, 2024 - Learn how to use the gzip and gunzip utilities to compress and uncompress files and folders from the command line in Linux. Explore compressing individual files and multiple files in subdirectories using wildcard expansion. Further, discover alternatives to gzip, such as Zip and 7-Zip, and ...
🌐
4D
discuss.4d.com › english community
Compress more than 1 file on a Gzip files - English Community - 4D Forum
November 25, 2022 - Hello. I need to gzip various .xml files into only one compressed gzip file. Is there any way ? T.I.A.
Find elsewhere
🌐
Julia Programming Language
discourse.julialang.org › general usage
Multiple files in a gzip archive - General Usage - Julia Programming Language
June 14, 2017 - Is it possible to create a single compressed archive that contains a number of text or csv files? It looks like gzip.jl only zips a single file at a time. Thanks!
🌐
Spiceworks
community.spiceworks.com › software & applications
How to gzip Multiple Files into Unique Zipped Files in One Shot? - Software & Applications - Spiceworks Community
October 22, 2009 - Hi Guys, If let’s say I have three files in one directory, A , B and C, I want to zip them to.gz as A.gz, B.gz and C.gz. Is there any command to do this in one shot, rather key in each command for each file? as I have m…
🌐
Quora
quora.com › How-do-I-gzip-multiple-files-in-Linux
How to gzip multiple files in Linux - Quora
Answer (1 of 6): Gzip is one of the most popular compression algorithms that allow you to reduce the size of a file and keep the original file mode, ownership, and timestamp. Gzip also refers to the .gz file format and the gzip utility used to compress and decompress files. If you want to compr...
🌐
Linuxize
linuxize.com › home › linux commands › gzip command in linux
gzip Command in Linux | Linuxize
April 24, 2026 - gzip compresses only single files. If you want to compress multiple files or a directory into one archive, you need to create a Tar archive first and then compress the .tar file with gzip.
🌐
Conrad Akunga
conradakunga.com › blog › how-to-compress-multiple-files-using-gzip-in-c-net
How To Compress Multiple Files Using GZip In C# & .NET | Conrad Akunga - Building Software In .NET
January 12, 2026 - You can create a gzip file from multiple source files by Tar-ing the files first using a TarWriter and then gzip-ing them using a GzipStream
🌐
GitHub
github.com › nodeca › pako › issues › 285
how to gzip multiple files? · Issue #285 · nodeca/pako
March 9, 2024 - how to gzip multiple files?#285 · Copy link · ralyodio · opened · on Mar 9, 2024 · Issue body actions · Can I have more than one file in a gzip file? No one assigned · No labels · No labels · No type · No projects · No milestone · None yet · No branches or pull requests ·
Author   nodeca
🌐
Reddit
reddit.com › r/bash › how to produce a single .gz file from multiple files?
r/bash on Reddit: How to produce a single .gz file from multiple files?
March 19, 2022 -

Sample file

$ ls -1
file-1
file-2

If I just use gzip file-*, the original files will be removed and replaced with individual .gz file

$ gzip file-*
$ 
$ ls -1
file-1.gz
file-2.gz
$ 

Is it possible to have a single .gz file while retaining the original files?

Desired output
$ ls -1

file-1
file-2
all.gz

Thanks

🌐
JavaPointers
javapointers.com › java › java-core › how-to-compress-files-in-gzip-in-java
How to compress files in GZIP in Java - JavaPointers
October 3, 2020 - As per the definition of GZIP in Wikipedia, GZIP is normally used to compress a single file. But we can compress multiple files by adding them in a tarball (.tar) before we compress them into a GZIP file.
🌐
LabEx
labex.io › lesson › compressed-archives-tar
tar and gzip - Packages | Linux Journey
This will create mycoolfile.gz and remove the original. To decompress the file, you can use gunzip: ... While gzip is great for compression, it cannot bundle multiple files into a single archive. For that, we use the tar (Tape Archive) utility.
🌐
GNU
gnu.org › software › gzip › manual › html_node › Advanced-usage.html
Advanced usage (GNU Gzip)
Next: Environment, Previous: Invoking gzip, Up: GNU Gzip: General file (de)compression [Contents][Index] Multiple compressed files can be concatenated. In this case, gunzip will extract all members at once. If one member is damaged, other members might still be recovered after removal of the ...
🌐
Yctct
yctct.com › compress-folder-with-gzip
Compress multiple directories (folders) with gzip - yctct
October 26, 2023 - gzip only compresses a file into an archive, not a collection of file or directories. So you need to use the utility tar to store multiple files or directories into one file before compressing them.
🌐
TecMint
tecmint.com › home › linux commands › 13 practical examples of using the gzip command in linux
13 Gzip Command Examples [Compress Files in Linux]
July 14, 2023 - So, first, let’s create multiple copies of the file using the following cp command: $ cp alma-linux.iso alma-linux-1.iso $ cp alma-linux.iso alma-linux-2.iso $ cp alma-linux.iso alma-linux-3.iso · Next, let’s compress the three files using the below command: $ gzip alma-linux-1.iso alma-linux-2.iso alma-linux-3.iso $ ls -l