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.
> I still do the ol' pipe dance when de-compressing archives, like this:
Same here. Old habits die hard, I suppose.
Just use dtrx (do the right extraction) via `pip install dtrx`. Makes life much easier.
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.)
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.
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.
And the 'z' flag is unnecessary; gnu tar is smart enough to figure that out on its own.
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.
For quick reference, since it seems to be hard[1], these are the flags you'll most need in tar:
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:
[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.