How to install and get xz
in OS X… It’s not difficult since there is a pkg-file to just download and install.
Tarballs
When downloading or creating archives, you may see/use some different extensions like tar.gz
, tar.bz2
etc. Tar is more like the container and the final extension is the compression being used - gzip
, bzip2
etc.
Example
You might compress a folder into a tar.gz
(gzip) like:
tar -zcvf fooBar.tar.gz --exclude ".DS_Store" --exclude "._*" "fooBar";
And extract it like:
tar -zxvf fooBar.tar.gz
c
is compressingx
is extracting
Same thing with tar.bz2
(bzip2), like:
tar -jcvf fooBar.tar.bz2 --exclude ".DS_Store" --exclude "._*" "fooBar";
tar -jxvf fooBar.tar.bz2
--exclude ".DS_Store" --exclude "._*"
will exclude .DS_Store and AppleDouble files.
You can also put in your ~/.bashrc
…or ~/.bash_profile
if you are using that one.
# No .DS_Store etc in "tar"
export COPY_EXTENDED_ATTRIBUTES_DISABLE=true
XZ
XZ Utils is free general-purpose data compression software with a high compression ratio. XZ Utils were written for POSIX-like systems, but also work on some not-so-POSIX systems. XZ Utils are the successor to LZMA Utils.
xz
can create much smaller archives, which is great if you have many. So when using gz
/bz2
it is actually a really waste of disk space.
There’s a great article over at “imoverclocked” called: For the love of bits, stop using gzip!
Install
So, how to install it in OS X… It’s not included in OS X by default, so head over to XZ Utils - there’s a link to an OS X package file at SourgeForge: Mac OS X Packages. At the time of writing the version is 5.0.7.
Download and install the package. It will install in: /usr/local/bin
$ which xz
/usr/local/bin/xz
For Linux/*BSD… If not already installed, you’ll find it in your package manager (eg pacman, dnf, apt etc).
Usage
Refer to the manual for all the options. It’s great and extensive, but here’s an example:
tar -cvf - "folder" | xz -4e > "folder".tar.xz;
tar -xvf folder.tar.xz folder
-4e
is the level of compression. Like:-2e
for less compression etc.
git
If you are using git
you can add to your ~/.gitconfig
:
[tar "tar.xz"]
command = xz -c
That makes xz
usable with git archive
. I have a function called gitArchive() in my ~/.bash_git
file, but otherwise it’s something like:
git archive --format=tar.xz -o ../RepoName.tar.xz --prefix=RepoName/ master;
That will put the archive in the parent folder, right next to your repository.