Some introductory tips on using 'tar' compression

May 16, '02 08:56:27AM

Contributed by: willie

I have been an off & on *nix user since the early 90s. I have used various versions, but only sporadically. It has been over four years since I used *nix with any regularity and I love having the ability in MacOSX.

I gleaned this info many years ago from various sources. Unfortunately I don't know who all contributed. I simply made myself a text file called "tgz notes" and have kept it all these years for those times when I couldn't remember how I did this.

Read the rest of the article for some different examples of how to use 'tar'.

To tar the current directory into one file and save the new file in the parent directory:

 % tar cf - . > ../filename.tar
To then zip the new file:
 % cat ../filename.tar | gzip > ../filename.tgz
To do both at the same time:
 % tar cf - . | gzip > ../filename.tgz
To extract, first change to the location you want the files (ie. create the outermost directory of the archive and then cd to it) and then:
 % zcat /some/path/filename.tgz | tar xvf -
So to archive the entire file structure within a directory:
 % cd /some/path/directory
% tar cf - . | gzip > ../directory.tgz
You end up with a new file named /some/path/directory.tgz. Then you do the following to put the directory structure somewhere else:
 % cd /new/location
% mkdir new_directory
% cd directory
% zcat /some/path/directory.tgz | tar xvf -
And you end up with the identical structure at both places, /some/path/directory and /new/location/directory.

[Editor's note: Although basic for experienced UNIX users, these tar tips should be helpful to those new to this world on the Mac.]

Comments (11)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20020516085627363