by lucb1e · 13y ago · 0 comments
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.
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' ..
Same here. Old habits die hard, I suppose.
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.
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.