Create tar archive with xz compression?
Looking at the source code for the libarchive package from Apple Open Source for OS X 10.8.5, 10.9, 10.10, and macOS 10.12.3, of which contains the source code for bsdtar, it includes the ability to use xz compression directly in tar
, however it was not implemented at compile time until OS X 10.9.0 and later. Although the manual page bsdtar.1 doesn't show the -J, --xz
options even though it's in the bsdtar.c source code.
To create an xz
compressed tar
archive in OS X 10.9 or later use the following syntax examples:
tar -cJf filename.tar.xz /path/to/folder_or_file ...
Or:
tar --xz -cf filename.tar.xz /path/to/folder_or_file ...
Example:
tar -cJf Documents.tar.xz "$HOME/Documents"
Or:
tar --xz -cf Documents.tar.xz "$HOME/Documents"
I also checked the Documents.tar.xz
file after it was created in a Hex Editor and it did have the proper header which included the expected 7zXZ
portion of the signature.