• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Techgoeasy

Techgoeasy

Learn Oracle, PHP, HTML,CSS,Perl,UNIX shell scripts

  • Home
  • Oracle
    • Oracle database
    • Oracle Ebusiness Suite
    • Oracle weblogic
    • Oracle Performance Tuning
    • Oracle Hyperion
    • Oracle Cloud Tutorials
  • SQL
  • interview questions
  • Linux
  • PHP and HTML
  • Downloads
  • General
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

June 28, 2020 by techgoeasy Leave a Comment

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

Filed Under: Unix command and scripts

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar



Subscribe to our mailing list

Enter your email address to subscribe to this blog and receive notifications of new posts by email

Recent Posts

  • How to generate sql monitor report in Oracle
  • How to find the long running (longops session) in Oracle
  • How to find concurrent request id from Sid or spid
  • how to check recycle bin in oracle: Purge, enable/disable
  • how to check fra size in oracle: Location, usage, change size

Copyright © 2023 : TechGoEasy

  • Hire me
  • Privacy Policy
  • Contact Us
  • New? Start Here
  • About Us