Comment by porridgeraisin

1 day ago

Personally I never understood the problem with tar balls.

The only options you ever need are tar -x, tar -c (x for extract and c for create). tar -l if you wanna list, l for list.

That's really it, -v for verbose just like every other tool if you wish.

Examples:

  tar -c project | gzip > backup.tar.gz
  cat backup.tar.gz | gunzip | tar -l
  cat backup.tar.gz | gunzip | tar -x

You never need anything else for the 99% case.

For anyone curious, unless you are running a 'tar' binary from the stone ages, just skip the gunzip and cat invocations. Replace .gz with .xz or other well known file ending for different compression.

  Examples:
    tar -cf archive.tar.gz foo bar  # Create archive.tar.gz from files foo and bar.
    tar -tvf archive.tar.gz         # List all files in archive.tar.gz verbosely.
    tar -xf archive.tar.gz          # Extract all files from archive.tar.gz

  • > tar -cf archive.tar.gz foo bar

    This will create an uncompressed .tar with the wrong name. You need a z option to specify gzip.

> tar -l if you wanna list, l for list.

Surely you mean -t if you wanna list, t for lisT.

l is for check-Links.

     -l, --check-links
             (c and r modes only) Issue a warning message unless all links to each file are archived.

And you don't need to uncompress separately. tar will detect the correct compression algorithm and decompress on its own. No need for that gunzip intermediate step.

  • > -l

    Whoops, lol.

    > on its own

    Yes.. I'm aware, but that's more options, unnecessary too, just compose tools.

    • That's the thing. It’s not more options. During extraction it picks the right algorithm automatically, without you needing to pass another option.

Yeah I never really understood why people complain about tar; 99% of what you need from it is just `tar -xvf blah.tar.gz`.

  • What value does tar add over plain old zip? That's what annoys me about .tar files full of .gzs or .zips (or vice versa) -- why do people nest container formats for no reason at all?

    I don't use tape, so I don't need a tape archive format.

    • A tar of gzip or zip files doesn't make sense. But gzipping or zipping a tar does.

      Gzip only compresses a single file, so .tar.gz lets you bundle multiple files. You can do the same thing with zip, of course, but...

      Zip compresses individual files separately in the container, ignoring redundancies between files. But .tar.gz (and .tar.zip, though I've rarely seen that combination) bundles the files together and then compresses them, so can get better compression than .zip alone.

    • The zip directory itself is uncompressed, and if you have lots of small files with similar names, zipping the zip makes a huge difference. IIRC in the HVSC (C64 SID music archive), the outer zip used to save another 30%.

    • Plain old zip is tricky to parse correctly. If you search for them, you can probably find about a dozen rants about all the problems of working with ZIP files.

The problem is it's very non-obvious and thus is unnecessarily hard to learn. Yes, once you learn the incantations they will serve you forever. But sit a newbie down in front of a shell and ask them to extract a file, and they struggle because the interface is unnecessarily hard to learn.

  • It's very similar to every other CLI program, I really don't understand what kind of usability issue you're implying is unique to tar?

    • As has been clearly demonstrated in this very thread, why is "Please list what files are in this archive" the option "-t"?

      Principle of least surprise and all that.

      1 reply →

it was just a reference to xkcd#1168

I wasn't expecting the downvotes for an xkcd reference