In continuation of our series of Linux tutorial,I am here presenting the Compress and Uncompress command in Linux
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.
compress [ -fv ] [ file ... ]
uncompress [ -cfv ] [ file ... ]
-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
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 -