How about just this?

$ gunzip *.txt.gz

gunzip will create a gunzipped file without the .gz suffix and remove the original file by default (see below for details). *.txt.gz will be expanded by your shell to all the files matching.

This last bit can get you into trouble if it expands to a very long list of files. In that case, try using find and -exec to do the job for you.


From the man page 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.

Note about 'original name'

gzip can store and restore the filename used at compression time. Even if you rename the compressed file, you can be surprised to find out it restores to the original name again.

From the gzip manpage:

By default, gzip keeps the original file name and timestamp in the compressed file. These are used when decompressing the file with the -N option. This is useful when the compressed file name was truncated or when the time stamp was not preserved after a file transfer.

And these file names stored in metadata can also be viewed with 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
Answer from gertvdijk on Stack Exchange
Top answer
1 of 4
70

How about just this?

$ gunzip *.txt.gz

gunzip will create a gunzipped file without the .gz suffix and remove the original file by default (see below for details). *.txt.gz will be expanded by your shell to all the files matching.

This last bit can get you into trouble if it expands to a very long list of files. In that case, try using find and -exec to do the job for you.


From the man page 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.

Note about 'original name'

gzip can store and restore the filename used at compression time. Even if you rename the compressed file, you can be surprised to find out it restores to the original name again.

From the gzip manpage:

By default, gzip keeps the original file name and timestamp in the compressed file. These are used when decompressing the file with the -N option. This is useful when the compressed file name was truncated or when the time stamp was not preserved after a file transfer.

And these file names stored in metadata can also be viewed with 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
2 of 4
10

Use this command to gunzip (unzip gz files) all files in the current directory and keep the original ones:

gunzip -k *.gz
🌐
GitHub
gist.github.com › alexrpagan › 7740607
Gunzip all files in a directory in parallel · GitHub
Gunzip all files in a directory in parallel. GitHub Gist: instantly share code, notes, and snippets.
🌐
YouTube
youtube.com › roel van de paar
Unix & Linux: gunzip all .gz files in directory (3 Solutions!!) - YouTube
Unix & Linux: gunzip all .gz files in directory (3 Solutions!)Helpful? Please support me on Patreon: https://www.patreon.com/roelvandepaarWith thanks & prai...
Published   August 14, 2020
Views   28
🌐
GeeksforGeeks
geeksforgeeks.org › linux-unix › gunzip-command-in-linux-with-examples
gunzip Command in Linux with Examples - GeeksforGeeks
May 13, 2026 - Automatically overwrites existing files without prompting for confirmation. Useful in scripts or batch operations where manual confirmation isn’t possible. ... Decompresses all .gz files within the specified directory and its subdirectories.
Find elsewhere
🌐
MathWorks
mathworks.com › matlab › programming › files and folders › file compression
gunzip - Extract contents of GNU zip file - MATLAB
gunzip(gzipfilenames) extracts the archived contents of each file in gzipfilenames to the folder containing gzipfilenames.
🌐
Unix.com
unix.com › unix for beginners q & a › unix for dummies questions & answers
gzip all the files in a directory - UNIX for Dummies Questions & Answers - Unix Linux Community
October 20, 2017 - Hi, There are multiple files in a directory with different names.How can they be gzipped such that the timestamp of the files is not changed.
🌐
GitHub
gist.github.com › kbbgl › 17099d6cafe16b441b1c6247d4850bef
[gunzip all .gz files in current directory] #gzip #bash · GitHub
Save kbbgl/17099d6cafe16b441b1c6247d4850bef to your computer and use it in GitHub Desktop. Download ZIP · [gunzip all .gz files in current directory] #gzip #bash · Raw · gunzipAll.sh · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below.
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › gunzip command in linux with examples
Gunzip Command in Linux With Examples {8 Examples}
December 19, 2025 - When running gunzip with an archive name but without any options, or with -d, the command has no output. The only way to verify the outcome is to list the files in the current working directory or with the -v option to get a verbose output.
🌐
TutorialsPoint
tutorialspoint.com › using-gzip-and-gunzip-in-linux
Using gzip and gunzip in Linux
March 24, 2023 - This command creates a new compressed archive named archive.tar.gz that contains all files and directories in the directory/. The c option tells tar to create a new archive, z option tells tar to use gzip compression, and f option specifies the name of the output file. To extract a compressed archive created with gzip ? ... # Decompress multiple files gunzip *.gz # Decompress while keeping compressed file gunzip -k file.txt.gz # Test compressed file integrity gunzip -t file.txt.gz # Force decompression gunzip -f file.txt.gz
🌐
Quora
quora.com › What-is-the-Linux-command-to-untar-all-gz-files-in-a-directory
What is the Linux command to untar all .gz files in a directory? - Quora
Answer (1 of 3): As a friend of mine used to say : “There are many ways to skin a cat" You could use the asterisk like: [code]gunzip *.gz [/code]Or for tar.gz archives [code]tar xfz *.tar.gz [/code]You could also indicate the full path… But what if you have a direct ory full of stuff plus the...
🌐
LinuxBlog
linuxblog.io › home › how to gzip a directory using linux command line
How to Gzip a Directory Using Linux Command Line | LinuxBlog.io
September 11, 2025 - After running this command, gzip will compress all the files within the directory and its subdirectories. You’ll find that each file is individually compressed, and the original directory structure is preserved.
🌐
LinuxQuestions.org
linuxquestions.org › questions › linux-general-1 › unzipping-all-gz-files-in-all-subdirectories-172263
Unzipping all .gz files in all subdirectories
I was trying to make a backup of my system last night and I screwed up the gzip command and ended up compressing over half the files in my system. I