Posted by: jasonk2600 | December 10, 2009

Quickie HowTo – File Archives with Tar and Gzip

Synopsis

The process of creating a single file archive under Linux, UNIX, and *BSD environments differs slightly from Microsoft Windows based file archive utilities.  Under Windows the archiving and compressing of the files in the archive all take place at once, with one utility such as the ZIP format.  Linux, UNIX, and *BSD environments break the process down into two steps.  First the files are archived together (also known as a tarball) and are then compressed with any of a variety of compression algorithms.  This document will explain how to create and extract file archive (tarballs) that have been compressed with gzip.

 

Creating a File Archive

Despite sounding like a complex operation, creating a tar’ed and gzip’ed file archive is straight forward and simple. The example below will create a file archive named YourArchiveName.tar.gz that contains the files file1.txt and file2.txt within it.

# tar cvzf YourArchiveName.tar.gz file1.txt file2.txt

 

To create a file archive containing the entire contents of a directory (or multi directories) refer to the sample below. The sample command below creates a file archive named YourArchiveName.tar.gz that contains all of the files and directories within the /home/username directory.

# tar cvzf YourArchiveName.tar.gz /home/username/*

 

Extracting a File Archive

Extracting the tar’ed and gzip’ed file archives are as simple as creating them.  Simply instruction tar to extract the archive, instead of instructing tar to create the archive.  The sample command below will extract the files contained within the file archived name YourArchiveName.tar.gz to the current directory.

# tar xvzf YourArchiveName.tar.gz

 

It is also useful and simple to specify where the files within a file archive should be extracted to. This can be achieved with the “-C” command line option. The sample command below will extract the files and directories contained within the YourArchiveName.tar.gz file archive to the /home/username/ directory.

# tar xvzf YourArchiveName.tar.gz -C /home/username/

 

  [EoF]
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: