Untitled Document
gzip & gunzip Command

The gzip and gunzip - are the file compression/ uncompression commands , which reduces the file size stored in disk .On compression the new file with .gz extension is created .We have added some basic examples of these two commands in this page . Mostly people use tar and zip commands for file compression and archival .

command - gzip 

Example 1 -

This will compress the file user.txt and creates new file user.txt.gz and removes the orignal user.txt from current directory .

   gzip user.txt    
   output - user.txt.gz

Example 2 -

We can compress multiple files with gzip command

   gzip list.txt user.txt emp.csv   
   output - list.txt.gz user.txt.gz emp.csv.gz

Example 3 -

How much compression did we actually achieve for above files ? The -l option displays the compression .

   gzip -l list.txt.gz user.txt.gz emp.csv.gz  

Example 4 -

We can restore the orignal and uncompressed file using -d option of gzip command .

   gzip -d list.txt.gz  
   gzip -d list.txt.gz user.txt.gz emp.csv.gz  ------ Will restore Multiple files 

Example 5 -

We can compress entire directory and its sub-directory with -r option of gzip command .You need the -r option and the arguments to gzip must comprise at least one directory .

   gzip -r shell_progs    

Example 6 -

We can decompress entire directory and its sub-directory by combining -r with -d option of gzip command

   gzip -dr shell_progs    

command - gunzip

Example 1 -

This will uncompress the file user.txt.gz and restores the old file user.txt. and removes the orignal user.txt.gz from current directory .
   gunzip user.txt.gz
   output - user.txt

Example 2 -

We can uncompress multiple files with gunzip command

   gunzip list.txt.gz user.txt.gz emp.csv.gz  
   output - list.txt user.txt emp.csv

Example 3 -

We can decompress entire directory and its sub-directory with -r option of gunzip command

   gunzip -r shell_prog   

Example 4 -

To view compressed test files , we really don't need to gunzip ( decompressed ) them .In most cases we run gunzip command with -c option

   gunzip -c list.txt.gz   
Untitled Document