How to Compress and Archive Data in Linux RHEL-7
“Compress : compression is a way for reduce the size of files for consume the less storage , it’s performed by a program that uses a Formula or Algorithm to determine how to shrink the size of data “
Linux has multiple tools inbuilt for data compression.
Program Extention Short Option
1.gzip .gz z
2.bzip2 .bz2 j
3. X2 .xz J
Create a file for compress or you already have a heavy size file
In my case I am creating a blank file and use sequence command for make entries inside it for for make it heavy size .
#du –h file1
#seq 1000000 > file1
#du –h file1
Now We have to compress and extract our file with gzip
#gzip filename (For compress the file)
#gunzip filename.gz (For Decompress the file )
Same we can do with other tools as below .
Note : while we compressing our file the original files removed so keep the original file also we have to use below option in command .
#gzip –c filename > filename.gz
Now Perform Archiving
We generally perform archiving for combine multiple files and directoryinto a single file .
Note : don’t confuse in compress and archive as archive just make single file from multiple files it’s don’t compress the data size ,however we can do both with single command by using archive+compress options .
#touch file1 file2 file3
#mkdir dir1 dir2 dir3
#tar cvf mydata.tar file1 file2 file3 dir1 dir2 dir3
#tar tf mydata.tar (If we want to check content of any tar file )
#tar rf mydata.tar filename (for add data in exist tar file)
Now use compress and archive option together .
#tar cvfz filename.tar.gz filenames
#tar xvfz newdata.tar.gz (for extract a archive and compress file )
#tar xf mydata.tar (for extract a tar file )