Monday, May 14, 2012

Time to retrain the fingers

For years, no decades, I've typed tar tzf something, tar xzf something. Except when someone annoying sent an uncompressed tar file and I had to then go and take out the z in the middle.

Then came bzip2, and we learned tar tjf, tar xjf. OK, I could live with that. One emerging problem was that the tab completion now worked the wrong way around conceptually, because you had to pick and type the right letter first in order to see the appropriate set of files to unpack offered for completion.

Then came lzma, which was (quick, guess?), tar tJf, tar xJf. And then there was lzop, which was too boring to get its own letter, so you had to type out tar -x --lzop -f.

But lzma was short-lived, because then came xz, which was also J, because lzma was now too boring as well to get its own letter.

Oh, and there is also the old compress, which is Z, and lzip, which I'd never heard of.

But stop that. Now there is

 -a, --auto-compress
            use archive suffix to determine the compression program

This handles all the above compression programs, and no compression. So from now on, I always use tar taf and tar xaf. Awesome.

The finger movements will be almost the same on QWERTY and AZERTY, and easier than before on QWERTZ.

Actually, this option is already four years old in GNU tar. Funny I'd never heard of it until recently.

9 comments:

  1. You might like to know that 'tar tf' and 'tar xf' work fine with compressed files even without -a; you only need it when creating an archive.

    ReplyDelete
    Replies
    1. Oh thanks for that tip. I think I like the symmetry with 'a' though.

      Delete
  2. You can find atool ( http://packages.debian.org/squeeze/atool ) very handy.
    To pack just type in:
    $ apack archive.7z ./file1 ./file2
    and this tools create 7zip archive from files
    or like this:
    $ apack archive.tgz ./file1 ./file2
    for tar.gz archive

    there is also aunpack tool, just give it a try.

    ReplyDelete
  3. You forgot the brief time when bzip2 had -I.

    ReplyDelete
  4. Thanks for the tip :) Btw, found this when I came home and saw the article slowly output by xscreensaver "apple ][" saver :p

    ReplyDelete
  5. Thanks for mentioning it, I’ve just added the ‘a’ flag to paxtar (Debian wheezy and up, package “pax”).

    However! I am still of the opinion that, when *creating* an archive, one shall always create to stdout and pipe that through an explicit compressor. Otherwise you get gzip -6 (laughable compression) and xz -6 (overkill for a lot of things).

    paxtar -cf - foo | gzip -n9 >foo.tgz

    find foo -type f | sort | paxcpio -oHustar | xz -2e >foo.txz

    These are examples. (pax, paxtar and paxcpio also support archive normalisation, that is, flags for things like setting uid and gid to 0, mtime to 0, not storing the user and group id names (only numbers), etc. and compression ratio _can_ increase when the files are ordered (instead of “sort” above) correctly.) By the way, xz -2 is not slower than gzip -9 and compresses not worse. (xz -e is slower, and higher numbers are NOT always better with xz, see its manpage.)

    PS: Posting with OpenID (using Launchpad’s) is impossible here.

    ReplyDelete
  6. Since which version GNU tar has supported that option?

    ReplyDelete
    Replies
    1. Thanks! That's why I could not find that option in RHEL 5.

      Delete