Andrew Mercer
on this page

Universal Extractors

When you just need to get the files out — or you don't know what format something is — these tools save you from remembering a dozen different flag sets.

bsdtar (libarchive)

The tar used by macOS, FreeBSD and Windows. On Linux it's usually packaged as libarchive-tools.

bsdtar -xf anything            # tar (any compression), zip, 7z, cpio, iso, ar, xar, cab, partial rar, ...
bsdtar -tf anything            # list
bsdtar -xf file.zip -C dest/
bsdtar -cf out.zip --format zip dir/   # it can write several formats too
bsdtar -cf out.7z --format 7zip dir/

Its read support for zip, 7z and iso makes bsdtar -xf a good single command to remember.

7-Zip

7z x anything                  # zip, 7z, rar, iso, cab, msi, dmg, vhd, wim, xar, ...
7z l anything

See 7-Zip.

unar / lsar

The Unarchiver's command-line tools. Open source, with excellent support for old and obscure formats (StuffIt, LHA, ARJ, ZOO, ARC) and automatic filename-encoding detection.

unar archive.ext               # creates a containing folder when needed
unar -o dest/ archive.ext
unar -p 'pass' archive.ext     # password
lsar archive.ext               # list
lsar -j archive.ext            # JSON listing

ouch

"Obvious Unified Compression Helper", a Rust CLI that infers the format from the file extension, for both compressing and decompressing.

ouch compress src/ out.tar.zst
ouch compress a.txt b.txt out.zip
ouch decompress anything.tar.xz
ouch decompress file.zip --dir dest/
ouch list archive.7z

Supports tar, zip, 7z, gzip, bzip2, xz, lzma, zstd, lz4, snappy, brotli and more, depending on the build.

atool

A Perl wrapper that calls the right underlying tool. It extracts into a subdirectory when an archive doesn't have a single top-level directory, which protects you from tarbombs.

aunpack archive.ext            # extract
apack out.tar.gz files...      # create (format from extension)
als archive.ext                # list
acat archive.ext file          # print a member
adiff a.tar.gz b.zip           # compare two archives

dtrx

"Do The Right Extraction": always extracts into a single directory, fixes permissions, and can extract archives nested inside archives.

dtrx archive.ext
dtrx -r archive.ext            # recursive

Choosing

Need Tool
One command for common formats, already installed on macOS/BSD bsdtar -xf
Windows-heavy formats (cab, msi, wim, dmg) 7z x
Old Mac/DOS/Amiga formats or garbled filenames unar
Same syntax to create and extract ouch
Tarbomb protection by default aunpack, dtrx, unar

See also