lots of tech info here

Quick references for tar, gzip and bzip2

Archival and zipping software

This is a list of commands that I use frequently for these archival/compression programs - tar, gzip and bzip2. You can get a more accurate description from the man pages (i.e. man tar or man gzip). If you are using Windows, you can download and use 7-zip to create or open .tar.gz or .tar tarballs.

Creating Archives

To archive directories dir1, dir2, dir3 into archive backupjan.tar

  tar -cvf backupjan.tar dir1 dir2 dir3

To archive all files and directories into backupjan.tar

  tar -cvf backupjan.tar *

To create backupjan.tar.bz2 from files file1, file2 and file3

  tar -cvjf backupjan.tar.bz2 file1 file2 file3

To gzip backupjan.tar

  gzip -c backupjan.tar

It will create backupjan.tar.gz.

To gzip with maximum compression, use -9 option

  gzip -9 backupjan.tar

To gzip multiple files (*.log) older than 1 day with a single command

  find . -name "*.log" -mtime 1 -type f -exec gzip {} \;

Extract/Untar Archives

To untar backupjan.tar into the current directory

  tar -xvf backupjan.tar

To untar backupjan.tar.bz2 into the current directory

  tar -xjvf backupjan.tar.bz2

To untar backupjan.tar.gz into the current directory

  tar -xzvf backupjan.tar.gz

To gunzip backupjan.tar.gz without extracting the tar

  gunzip backupjan.tar.gz

View contents of Archive

To view the contents of backupjan.tar

  tar -tf backupjan.tar

To read the contents of sitemap.gz (assuming that the uncompressed form is in ASCII text)

  zcat sitemap.gz

Delete files from Archive

To delete file1 and file2 from backupjan.tar

  tar -f backupjan.tar --delete file1 file2

Add files to existing Archive

To add file file1 and file2 to backupjan.tar

  tar -rf backupjan.tar file1 file2


Posted on 01 Jan 2010

TAGS: tar, gzip, bzip2

If you liked this article, subscribe to our Feed, follow us on Twitter (@aruljohn) and/or join our Facebook Page.

Share this with Others