For compress file or directory, GNU tar command is best for this work. It can be use on remote Linux or UNIX server. It does two things for you:
– Create the archive
– Compress the archive
Following is syntax of the tar command:
tar -zcvf archive-name.tar.gz your-directory-name
-z: Compress archive using gzip program
-c: Create archive
-v: Verbose i.e display progress while creating archive
-f: Archive File name
For example, you have directory called /home/himanshu/data and you would like to compress this directory then so you can type tar command as follows:
$ tar -zcvf data-06032014.tar.gz /home/himanshu/data
Above command will create an archive file called data-06032014.tar.gz in current directory. If you wish to restore your archive then you need to use following command (it will extract all files in current directory):
$ tar -zxvf data-06032014.tar.gz
-x: Extract files
If you wish to extract files in particular directory, for example in /tmp then you need to use following command:
$ tar -zxvf data-06032014.tar.gz -C /tmp
$ cd /tmp
$ ls –
How to grep from a GZ file on Linux System?
There are few ways by which you can grep from GZ files on Linux .The best way is to use the zgrep command as follows.
zgrep -c “post-offers HTTP/1.1” access_log.11.gz
In the above example i used the grep command on access_log.gz file to get the count of post-offers in that file.