xar
Create and extract archive files
TLDR
Create a xar archive of all files in a given directory
List the contents of a given xar archive
Extract the contents of a given xar archive to the current directory
SYNOPSIS
Creating an archive:
xar -c -f archive_file [options] [file ...]
Extracting from an archive:
xar -x -f archive_file [options] [file ...]
Listing archive contents:
xar -t -f archive_file [options]
Signing or verifying an archive:
xar -s command -f archive_file [options]
PARAMETERS
-c
create
Creates a new archive.
-x
extract
Extracts files from an archive.
-t
list
Lists the table of contents of an archive.
-f
file
Specifies the archive file to operate on.
-v
verbose
Enables verbose output, showing details of operations.
-s
signature
Performs a signature operation on the archive. command can be 'create' to sign, or 'verify' to check a signature.
-C
change directory
Changes to the specified directory before adding files to the archive. Useful for relative paths.
-j
bzip2 compression
Uses bzip2 compression for files within the archive.
-z
gzip compression
Uses gzip compression for files within the archive.
-p
preserve permissions
Preserves file permissions, ownership, and modification times during extraction.
-D
do not flatten
Do not flatten directories. Typically used when extracting specific files.
DESCRIPTION
xar is an open-source archiver and extensible archive format, conceptually similar to tar or zip. A key distinguishing feature is its XML-based table of contents, which is stored at the beginning of the archive. This design makes it easy for other applications to parse and understand the archive's structure without reading the entire file.
xar supports checksums for individual files and can optionally include an SHA1 hash of the entire archive in its header for integrity verification. Its extensible schema allows for custom metadata and features. While xar can be used as a general-purpose archiving tool, it is most notably utilized by Apple for creating macOS installer packages (.pkg files) and storing bill of materials (.bom) data.
CAVEATS
xar is primarily developed and used by Apple, making it a standard component of macOS for package management and system imaging. While it is open-source and available on Linux, its adoption for general-purpose archiving is less widespread compared to tools like tar or zip. Users on Linux might need to install it from their distribution's repositories, and its full feature set, especially regarding signing, might depend on specific library availability (e.g., OpenSSL). Its unique XML-based header can be advantageous for programmatic access but may be less intuitive for command-line users accustomed to simpler archive formats.
XML TABLE OF CONTENTS
xar archives begin with an XML-based table of contents (TOC). This TOC describes the archive's structure, lists all files, their metadata (permissions, timestamps), and checksums. This design allows applications to easily parse the archive's contents without decompressing or reading the entire archive, facilitating selective extraction and inspection.
CHECKSUMS AND INTEGRITY
Each file within a xar archive includes its own checksum. Additionally, the archive can contain an optional SHA1 hash of its entire content. This robust integrity checking mechanism ensures that data corruption can be detected, making xar suitable for distributing sensitive or critical software.
HISTORY
The xar utility and format originated from Apple Inc., designed to be a flexible and extensible archiving solution for its operating system. It became a cornerstone of macOS installer packages, with .pkg files essentially being xar archives containing the application payload and bill of materials (.bom files, which are themselves xar archives). Its development aimed to provide a more robust and introspectable archive format than previous methods, leveraging XML for a structured table of contents and built-in support for digital signatures, crucial for software distribution and security on macOS.