Home » Unix command and scripts » How to create ,List and unzip Tar.gz file in Linux

How to create ,List and unzip Tar.gz file in Linux

The GNU tar command included with Linux distributions has integrated compression(.gz) .It can create a .tar archive and then compress it with gzip or bzip2 compression in a single command.  The resulting file is a .tar.gz file or .tar.bz2 file. we will learn about how to create ,List and unzip Tar.gz file in Linux

How to create the tar.gz file

It uses the extra letter z to achieve it

tar -czvf directory.tar.gz <directory Name>
GNU tar cvfz command | unzip Tar.gz file in Linux

How to list tar.gz file

tar -ztvf  <tar gz file>
GNU tar tvfz command

How to compress using bzip2 compression

One more option for compression is  available bzip2, it can be achieved using -j option

tar -cjvf directory.tar.bz2 <directory Name>

How to exclude some files

On some occasion you may wish to compress an entire directory, but not include certain files and directories. You can do so by appending an –exclude switch for each directory or file you want to exclude.

tar -czvf directory.tar.gz <directory Name>  --exclude=*.txt

How to unzip Tar.gz file in Linux

tar -zxvf file.tar.gz

If it is required to extract few files only

tar -zxvf file.tar.gz file1 file2

If it is not possible to use the z option ,  we can use below option to compress the tar files also

tar compress directory command

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

Uncompress will go like

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

tar gzip command

tar -cvf - file1 file2 | gzip > file.tar.gz
tar gzip command linux

tar guzip command

gunzip -c file.tar.gz|tar -xvf -
tar gunzip command

Related articles 
Linux command for Oracle DBA
sed command in unix examples
basic unix command
loop in shell scripts
awk command in Unix
https://en.wikipedia.org/wiki/Bzip2

See also  how to start and stop httpd service

Leave a Comment

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

Scroll to Top