Home » Unix command and scripts » Compress And Uncompress in Linux

Compress And Uncompress in Linux

In continuation of our series of Linux tutorial,I am here presenting the Compress and Uncompress command in Linux

Compress,Uncompress command

compress – The compress utility will attempt to reduce the size of the named files. File will be replaced by one with the extension .Z, while keeping the same ownership modes, change times and modification times.

uncompress – The uncompress utility will restore files to their original state after they have been compressed using the compress utility.

SYNTAX:
compress [ -fv ] [ file ... ]

uncompress [ -cfv ] [ file ... ]

Options:
-c Write to the standard output. No files are changed.
-f When compressing, force compression of file, even if it does not actually reduce the size of the file, or if the corresponding file.Z file already exists.
-v Verbose. Write to standard error messages concerning the percentage reduction or expansion of each file.

Few things to note

(1) when compress or uncompress we should have the disk space to hold both the compress and uncompress copy
(2) if it fails,it get revert back to original status

Compression
$ls
alert_CHECK.log
$compress alert_CHECK.log
$ ls
alert_CHECK.log.Z 
Uncompression
$ls
alert_CHECK.log.Z
$uncompress alert_CHECK.log.Z
$ ls
alert_CHECK.log 
 

We can use compress command to compress the tar file directory using PIPE also. Example shown below

tar compress directory command

tar -cvf - dir1 dir2 | compress > file.tar.Z
tar compress directory command

Similarly , we can use uncompress to uncompress the tar file using PIPE command.Example shown below

Uncompress will go like

uncompress -c file.tar.Z|tar -xvf  -
tar uncompress directory command

Also Read
awk command : Awk command in Unix or Linux is a powerful command for processing text. Learn about awk syntax, records, fields, line Separator with examples of awk in unix
split command
find command : find command in Unix with example,How to use find command in Unix.Unix find directory command,how to find find based on modified time
tr command in Unix : check out about tr command in Unix operating system , where all we can use and what all options are available in Linux/Unix
gzip and gunzip command in Linux
tee command in Unix

See also  RSYNC command – sync the data between two directories

Leave a Comment

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

Scroll to Top