There are two ways to create a compressed GZIP file in Unix and Linux operating system.
1.Create an uncompressed archive (.tar) file using #tar –cvf command and then compressed it with the help of ‘gzip’ command.
2.And the second way to create a compressed file is, use the #tar –cvzf command, after executing this command, you don’t need to compress it via additional tools like ‘gzip’. This will already create a compressed file such as yourfile.tar.gz or yourfile.tgz.
First Method to create a compressed GZIP file :-
First of all you need to create a uncompressed archive using #tar –cvf command as shown below:-
#tar –cvf myfile-13-12-2015.tar /etc/mysolutions/Mydata
The above command will create a uncompressed tar archive ‘myfile-13-12-2015.tar’ file for a directory ‘/etc/mysolutions/Mydata/’.
Then compress the recently created tar archive ‘myfile.-13-12-2015.tar’ file, by executing the following command:-
#gzip myfile-13-12-2015.tar
Second Method to create a compressed GZIP file :-
Execute one of the following command to create a compressed GZIP file:-
#tar –cvzf myfile-13-12-2015.tar.gz /etc/mysolutions/Mydata
OR
#tar –cvzf myfile-13-12-2015.tgz /etc/mysolutions/Mydata
The above command will create a compressed tar archive ‘myfile-13-12-2015.tar.gz’ or ‘myfile-13-12-2015.tgz’ file for a directory ‘/etc/mysolutions/Mydata/’.
To create a compressed (GZIP) archive of current directory, you need to execute the following command:-
#tar –cvzf myfile2-13-12-2015.tar.gz .
This will create a compressed archive ‘myfile2-13-12-2015.tar.gz’ file of present working directory( pwd ).
To create a compressed (GZIP) archive of current working directory in a different directory, you need to execute the following command:-
#tar –cvzf /etc/myarchive/myfile2-13-12-2015.tar.gz .
The above command will create a compressed archive ‘myfile2-13-12-2015.tar.gz’ file of present working directory( pwd ) in ‘/etc/myarchive/’ directory.