Home » Unix command and scripts » gzip and gunzip command in Linux

gzip and gunzip command in Linux

In continuation of our series of Linux tutorials,I am here presenting the gzip and gunzip commands in Linux

gzip and gunzip command

gzip: The gzip utility will attempt to reduce the size of the named files. The file will be replaced by one with the extension .gz, while keeping the same ownership modes, change times and modification times.

gunzip: The gunzip utility will restore files to their original state after they have been compressed using the gzip utility.

$ls
alert_CHECK.log 
$gzip alert_CHECK.log
$ ls
alert_CHECK.log.gz  

$ls
alert_CHECK.log.gz
$gunzip alert_CHECK.log.gz
$ ls
alert_CHECK.log 

The gzip command can be used with the tar command also to gzip the tar files. An example is shown below

tar gzip command

tar -cvf - file1 file2 | gzip > file.tar.gz
tar gzip command linux

A similar gunzip command can be used with the tar command also to unzip the tar files. An example is shown below

tar gunzip command

gunzip -c file.tar.gz|tar -xvf -
tar gunzip command

Difference between gzip and compress

Both the utility compress and gzip compress the file i.e serve the same purpose

(1) In general Compress will run faster and use less memory, but gzip will generally reach significantly higher levels of compression.
(2) Compress is an old algorithm while gzip is the new one

Also Read
Linux command for Oracle DBA
sed command in Unix examples
basic unix command
loop in shell scripts
awk command in Unix
tr command in Unix
https://en.wikipedia.org/wiki/Bzip2

See also  if condition in shell script

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top