← Back to context

Comment by jeanlucas

18 hours ago

nope, that would be handling tar balls

ffmpeg right after

Tough crowd.

fwiw, `tar xzf foobar.tgz` = "_x_tract _z_e _f_iles!" has been burned into my brain. It's "extract the files" spoken in a Dr. Strangelove German accent

Better still, I recently discovered `dtrx` (https://github.com/dtrx-py/dtrx) and it's great if you have the ability to install it on the host. It calls the right commands and also always extracts into a subdir, so no more tar-bombs.

If you want to create a tar, I'm sorry but you're on your own.

  • I used tar/unzip for decades I think, before moving to 7z which handles all formats I throw at it, and have the same switch for when you want to decompress into a specific directory, instead of having to remember which one of tar and unzip uses -d, and which one uses -C.

    "also always extracts into a subdir" sounds like a nice feature though, thanks for sharing another alternative!

  • > tar xzf foobar.tgz

    You don't need the z, as xf will detect which compression was used, if any.

    Creating is no harder, just use c for create instead, and specify z for gzip compression:

      tar czf archive.tar.gz [filename(s)]
    

    Same with listing contents, with t for tell:

      tar tf archive.tar.gz

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.

      2 replies →

  • > 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.

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

  • 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?

      2 replies →