News for hackers. Stuff that matters.
Re:Linux shell tips and tricks by lucb1e on Sunday November 24, 2013 @07:57AM (#6789493)
> Extract tar.gz in new directory: tar zxvf package.tar.gz -C new_dir

For quick reference, since it seems to be hard[1], these are the flags you'll most need in tar:

    c = create
    x = extract
    v = verbose
    z = gzipped; compressed.
    f = file
So for example `tar xf example.tar` will extract that tar file. Or `tar cf example.tar .` will pack all files in the current directory to example.tar. For compression and verbosity, it would be `tar zvcf example.tar.gz .`. The .gz at the end is optional, but now others can see what kind of archive it is. Extract .tar.gz files with `tar xzf example.tar.gz`.

For bonus points, here is a poor man's version of scp/rsync:

    # sending computer
    tar czf - . | openssl aes-128-cbc -k 'secret' | nc -l 1
    # receiving computer
    nc 192.168.1.102 1 | openssl aes-128-cbc -d -k 'secret' | tar xf -
[1] Obligatory xkcd https://xkcd.com/1168/

Edit: replaced all asterisks with a period (.) since it would become italics. Tar is recursive by default, so it should work the same.

Re:Linux shell tips and tricks by fit2rule on Sunday November 24, 2013 @11:42AM (#6790019)
Cheese note: I still do the ol' pipe dance when de-compressing archives, like this:

    gunzip -c somefile.tar.gz | tar xvf - 
The reason? Well, its like this: I learned it that way on machines that had, typically, about 4 megs available. So it used to be, back in the ol' days, that if you tried to do it like:

    tar xvzf somefile.tar.gz
.. you'd run out of RAM, get into swapfile sadness, and so on.

Piping it through the console first, used the tty-buffers, which blocked whenever exhaustion occurs, but nevertheless: recovered a lot smoother than when heavy swap was involved ..

Dunno if its still 'true' (could be a mythos I'm passing on from the old, drunk sysadmin I learned the rule from) but it aways bugs me when I forget to do it 'the new way' ..

Re:Linux shell tips and tricks by bediger4000 on Sunday November 24, 2013 @06:16PM (#6791624)
This is at least sometimes still true in corporate Linux environments. Giant, Immoral MegaCorps apparently can't be bothered to spring for big disks, so doing "tar xzf" or gunzipping something before un-tarring often fills up the filesystem. Embarassing, but true, given that you can hoof it to Office Depot and buy terabytes for a couple hundred, if they'd just let you.
Re:Linux shell tips and tricks by jlgaddis on Sunday November 24, 2013 @02:19PM (#6790673)
> I still do the ol' pipe dance when de-compressing archives, like this:

Same here. Old habits die hard, I suppose.

Re:Linux shell tips and tricks by parennoob on Sunday November 24, 2013 @09:38AM (#6789681)
Just use dtrx (do the right extraction) via `pip install dtrx`. Makes life much easier.
Re:Linux shell tips and tricks by voltagex_ on Sunday November 24, 2013 @11:20PM (#6792465)
GNU tar seems to have gained the a switch which will detect the right decompressor.

e.g.

tar axf linux.tar.gz

tar axf linux.tar.bz2

tar axf linux.tar.xz

will all work, assuming you have gzip, bzip2 and xz installed.

Re:Linux shell tips and tricks by deathanatos on Monday November 25, 2013 @04:02AM (#6793143)
Nowadays, `tar -xf foo.tar.gz` (at least in Linux) will auto-detect the gzipping and just do the right thing. I think it uses file extension, so I'd suspect it works for .bz2 and .xz too. (Not sure I'd use this for shell scripts, but for everyday command line it should work.)
Re:Linux shell tips and tricks by sobering on Sunday November 24, 2013 @11:18AM (#6789950)
I'd also add `-j' to that list.

j = bzip2

I find a lot of packages with the `.tar.bz2' extension. Just replace `z' with `j' in your tar command and you're good.

Re:Linux shell tips and tricks by lucb1e on Sunday November 24, 2013 @01:31PM (#6790490)
Can't edit my post anymore, but good tip! As dmd commented though, it seems tar automatically detects compression on files because of the file extension.
Re:Linux shell tips and tricks by dmd on Sunday November 24, 2013 @08:58AM (#6789610)
And the 'z' flag is unnecessary; gnu tar is smart enough to figure that out on its own.
Re:Linux shell tips and tricks by lucb1e on Sunday November 24, 2013 @08:59AM (#6789614)
Yesterday I got an error 'error: tar archive is compressed. Aborting' or something along those lines. When reading a file it might detect it because of the filename, but with stdin you need to specify the flag it seems.