Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
The gunzip
command in Linux is used to decompress files that have been compressed using the gzip
utility. The gzip
utility compresses files using the Lempel-Ziv (LZ77) algorithm, and the compressed files usually have a .gz
extension. The gunzip
command restores the original file by decompressing the compressed file. In this tutorial, we'll go over some basic usage examples for the gunzip
command.
To decompress a single file using gunzip
, simply provide the file as an argument:
gunzip file.gz
This will decompress file.gz
and create the original file file
in the same directory. The compressed file file.gz
will be removed.
You can decompress multiple .gz
files in a single command by providing multiple file names as arguments:
gunzip file1.gz file2.gz file3.gz
By default, gunzip
will remove the compressed file after decompressing it. If you want to keep the compressed file, use the -k
or --keep
option:
gunzip -k file.gz
If you want to decompress a file and store the decompressed file in a different directory, you can use the -c
option in combination with file redirection:
gunzip -c file.gz > /path/to/directory/file
This will decompress file.gz
and create the decompressed file in the specified directory without modifying the original compressed file.
gunzip
can also decompress files that don't have the standard .gz
extension. To do this, use the -S
or --suffix
option:
gunzip -S .custom file.custom
This command will decompress file.custom
and create the decompressed file file
.
In summary, the gunzip
command in Linux is a useful tool for decompressing files that have been compressed with the gzip
utility. By understanding its various options and arguments, you can efficiently decompress files, work with custom file extensions, and manage the output of decompressed files.
How to use the gunzip command in Linux:
gunzip
is a command-line utility in Linux used to decompress gzip files. It's often used in conjunction with the gzip
compression tool.
Example code:
gunzip filename.gz
Unzipping .gz files with gunzip:
Unzipping a .gz file is straightforward with the gunzip
command.
Example code:
gunzip file.gz
Decompressing gzip files using gunzip:
gunzip
can be used to decompress gzip files, which have the .gz
extension.
Example code:
gunzip data.gz
Handling compressed archives with gunzip in Linux:
gunzip
can handle compressed archives containing multiple gzip files. It's commonly used in combination with tar for extracting compressed tarballs.
Example code:
tar -xzf archive.tar.gz
Recursive unzipping with gunzip:
To recursively unzip all .gz files in a directory and its subdirectories, you can use the find
command.
Example code:
find /path/to/directory -type f -name "*.gz" -exec gunzip {} \;
Preserving original files during gunzip:
By default, gunzip
removes the original gzip file after decompressing. To preserve the original file, you can use the -k
option.
Example code:
gunzip -k data.gz
Viewing progress and status in gunzip command:
The gunzip
command doesn't provide a built-in progress indicator. However, you can use tools like pv
(Pipe Viewer) in combination with gunzip
to view progress.
Example code:
pv file.gz | gunzip > output_file
Extracting specific files from a gzip archive with gunzip:
If you have a gzip archive containing multiple files and you want to extract only specific files, you can use the -c
option to extract to standard output and then redirect the output.
Example code:
gunzip -c archive.gz file.txt > extracted_file.txt