Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Mar 1995 16:15:15 -0500 (EST)
From:      Chuck Robey <chuckr@Glue.umd.edu>
To:        aarone@homer.prahran.swin.edu.au
Cc:        FreeBSD-questions@freefall.cdrom.com
Subject:   Re: GZipping the contents of directories...
Message-ID:  <Pine.SUN.3.91.950309155827.14157A-100000@espresso.eng.umd.edu>
In-Reply-To: <MAILQUEUE-101.950309170900.384@h409-fs3.prahran.swin.edu.au>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 9 Mar 1995, Aaron Elliott. wrote:

> Hi All..
> 
>   I am trying to find a way to gzip a directory tree whilst
>   still keeping the files in that directory tree intact so when I
>   gunzip them, I get an exact copy of what I had formerly,
>   in the same tree...
> 
>   Like you can in pkzip etc..
> 
>   I can make it so it puts it all in one file, but it doesnt separate
>   it into is directories and files.. Its just a lump of files!
> 
>   I am running FreeBSD 1.1.5.1

This is commonly done in the Unix universe by the use of the 'tar' 
facility.  Tar originally stood for a contraction of 'Tape Archive', but 
it has proven to be a great general purpose utility to collect together 
files.

I would suggest reading the tar man page....but FreeBSD doesn't have 
one.  The tar FreeBSD uses is the GNU tar, and you can read the command 
parameters by typing 'tar --help' and catching the output in a file, to 
peruse later (it's more than a screenful).

Let my give you some example command lines, maybe this'll get you 
started.  To make a file called stuff.tar, that is an archive of the 
directory /usr/homes/myname/stuff, cd to the /usr/homes/myname directory.
>From there, issue the command:
tar -cf stuff.tar stuff

If you want to gzip stuff.tar, by all means do so, 'gzip stuff.tar'.  
It'll work fine.

You can gunzip it later, at the destination point, and then unpack the
archive with the command:

tar -xf stuff.tar.

You could just examine what's in the tar archive by typing:

tar -tf stuff.tar.

Lastly, you could unzip and unpack the archive in one fell swoop:

gunzip -c stuff.tar.gz | tar -xf -

The -c parameter to gunzip tells it to route it's output to stdout, 
instead of replacing the file stuff.tar.gz with stuff.tar, and the last
parameter to tar, '-', says to read the archive from the stdin (from the 
output of the gunzip command).  This will leave the original stuff.tar.gz 
in place, and create the new stuff directory.

One last warning.  Some folks don't encapsulate their archives in 
directories before they archive them, so if you don't check the filenames 
that are listed in an archive you are about to unpack, you could find 
that you've just polluted your current directory with a bunch of files.  
If you were in your home directory, that could be a real pain.  I always 
check an archive first:
gunzip -c <gzipped archive name> | tar -tvf -
and if I see the file names are all proceeded with a directory name, and 
I'm in csh, I then issue:
^tvf^xvf
to unpack.  If the filenames are listed without a leading directory, I 
first create one for the files, cd into it, then do the unpacking.

There are other nasties you could trip over.  I really suggest looking up 
tar in a good Unix system manager's book, you won't be wasting your time.

----------------------------+-----------------------------------------------
Chuck Robey                 | Interests include any kind of voice or data 
chuckr@eng.umd.edu          | communications topic, C programming, and Unix.
7608 Topton St.             |
New Carrollton, MD 20784    | I run Journey2 (Freebsd 2.0) and n3lxx
(301) 459-2316              | (FreeBSD 1.1.5.1) and am I happy!
----------------------------+-----------------------------------------------




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SUN.3.91.950309155827.14157A-100000>