[Techtalk] 'nother obvious newbie question

Kai MacTane kmactane at GothPunk.com
Tue Oct 2 10:47:26 EST 2001


At 10/1/01 09:29 PM , Rachel Herold wrote:
>help!
>okay, I get it installed, how come I can't figure out how to read the dern
>doc files?  I found a whole set of help files ending in .gz but haven't been
>able to figure out how to read/open them.  I've tried all the obvious
>things, a few non-obvious things (at least non-obvious to a windows person),
>but I give up and decided I shouldn't waste so much time (2 hours is enough)
>when I can ask someone.

Ah. What do with a .gz file is fairly obvious to an experienced Unix 
person... <wry grin> You just do a "tar -xvzf" on the sucker.

("Oh, of *course*," all the Windows people say in a voice heavy with sarcasm.)

Okay, here's the deal: the .gz extension means the file is a gzip, or GNU 
zip, file. (As you get used to Linux, you'll come to see that nearly 
anything with a "g" prefix means GNU-whatever.) This is the GNU equivalent 
of a WinZip file -- compressed, and (usually) containing multiple 
sub-files, even entire directory structures.

There are various ways to deal with such things (indeed, I sometimes think 
Perl's motto of "There's more than one way to do it" should have been 
Unix's instead), but the one I tend to use is:

    tar -xvzf file-to-open

This will unpack files and directories into the directory you're already 
in, but the convention in Unix-land is to make your archive files (gzips 
and others) so that the first thing they'll create is a subdirectory with 
an obvious name (usually matching the name of the zip-file itself, minus 
extension), and then put all other files and structures into there.

The reason I use that particular command line is because it will work just 
fine on practically all the various archive files you'll find: in addition 
to .gz, there are .tar.Z, .tgz, .tar.gz, and I think maybe one or two 
similar combinations. Plus there are just plain .tar files, which are 
essentially like a Windows Zip file (in the sense of packing multiple files 
into one), but with *no* compression. ("tar" in this case, stands for "Tape 
ARchive", and was originally designed to back stuff up to mag-tape.)

At any rate, if you have GNU tar on your system (which you almost certainly 
do if you're running any Linux distro), then "tar -xvzf archive-file" will 
work, without any reference to exactly how the thing was packed up.

A quick description of just what's going on in that command line is:

tar: the name of the command that both tars and untars stuff.
  -x: eXtract a file (other main options are Create and lisT file;
      see below for more on that)
  -v: Do it Verbosely (list files as tar is operating; not strictly
      necessary, but nice to have for some output).
  -z: Use Zip compression (i.e., if creating a file, compress it in
      addition to just glomming all the files into one; if extracting
      or listing, realize that the file was compressed, and use the
      Zip algorithm to uncompress).
  -f: What file to act on; must be followed *immediately* by the name
      of the archive file.

The fact that -f must be followed immediately by the name of the archive 
file is only of importance when you're creating a new archive. In that 
case, the command line is:

    tar -cvzf file-to-create  filespec-to-compress

"filespec" in that case means you can include wildcards. Most of the time, 
you'll just compress one entire subdirectory, so as to create the kind of 
archive that opens up as described above.

The -t flag is useful if you want to get an idea of what's in an archive 
file without actually opening the whole thing: it will simply list all the 
files inside the archive, then exit. You'll usually want to pipe this 
through your favorite pager program (such as more, or less), so:

    tar -tvzf file-I-just-downloaded | less

Hope that gives you the information you need!

                                                 --Kai MacTane
----------------------------------------------------------------------
"Playing dead and sweet submission,
  Cracks the whip deadpan on cue."
                                                 --Siouxsie and the
                                                   Banshees,
                                                  "Peek-a-boo"





More information about the Techtalk mailing list