Hack 49. Combine gzip, bzip2 with tar

by Ramesh

How to use gzip with tar?

Add option z to the tar command when dealing with tar.gz compressed file.

  1. # tar cvfz /tmp/my_home_directory.tar.gz /home/jsmith
  2.  
  3. # tar xvfz /tmp/my_home_directory.tar.gz
  4.  
  5. # tar tvfz /tmp/my_home_directory.tar.gz

Note: Using gzip is faster when compared to bzip2.

How to use bzip2 with tar?

Add option j to the tar command when dealing with tar.bz2 compressed file.

  1. # tar cvfj /tmp/my_home_directory.tar.bz2 /home/jsmith
  2.  
  3. # tar xvfj /tmp/my_home_directory.tar.bz2
  4.  
  5. # tar tvfj /tmp/my_home_directory.tar.bz2

Note: Using bizp2 gives higher level of compression when compared to gzip.