Tools to handle archives conveniently / / at 01:42 / / by abe

from the DWIM dept.

TL;DR: There’s a summary at the end of the article.

Today I wanted to see why a dependency in a .deb -package from an external APT repository changed so that it became uninstallable. While dpkg-deb --info foobar.deb easily shows the control information, the changelog is in the filesystem part of the package.

I could extract that one dpkg-deb , too, but I’d have to extract either to some temporary directory or pipe it into tar which then can extract a single file from the archive and sent it to STDOUT:

dpkg-deb --fsys-tarfile foobar.deb | tar xOf - ./usr/share/doc/foobar/changelog.Debian.gz | zless

But that’s tedious to type. The following command is clearly less to type and way easier to remember:

acat foobar.deb ./usr/share/doc/foobar/changelog.Debian.gz | zless

acat stands for “archive cat” is part of the atool suite of commands:

als lists files in an archive. $ als foobar.tgz drwxr-xr-x abe/abe 0 2012-11-15 00:19 foobar/ -rw-r--r-- abe/abe 13 2012-11-15 00:20 foobar/bar -rw-r--r-- abe/abe 13 2012-11-15 00:20 foobar/foo acat extracts files in an archive to standard out. $ acat foobar.tgz foobar/foo foobar/bar foobar/bar bar contents foobar/foo foo contents adiff generates a diff between two archives using diff(1). $ als quux.zip Archive: quux.zip Length Date Time Name --------- ---------- ----- ---- 0 2012-11-15 00:23 quux/ 16 2012-11-15 00:22 quux/foo 13 2012-11-15 00:20 quux/bar --------- ------- 29 3 files $ adiff foobar.tgz quux.zip diff -ru Unpack-3594/foobar/foo Unpack-7862/quux/foo --- Unpack-3594/foobar/foo 2012-11-15 00:20:46.000000000 +0100 +++ Unpack-7862/quux/foo 2012-11-15 00:22:56.000000000 +0100 @@ -1 +1 @@ -foo contents +foobar contents arepack repacks archives to a different format. It does this by first extracting all files of the old archive into a temporary directory, then packing all files extracted to that directory to the new archive. Use the --each ( -e ) option in combination with --format ( -F ) to repack multiple archives using a single invocation of atool . Note that arepack will not remove the old archive. $ arepack foobar.tgz foobar.txz foobar.tgz: extracted to `Unpack-7121/foobar' foobar.txz: grew 36 bytes apack creates archives (or compresses files). If no file arguments are specified, filenames to add are read from standard in. aunpack extracts files from an archive. Often one wants to extract all files in an archive to a single subdirectory. However, some archives contain multiple files in their root directories. The aunpack program overcomes this problem by first extracting files to a unique (temporary) directory, and then moving its contents back if possible. This also prevents local files from being overwritten by mistake.

(atool subcommand descriptions from the atool man page which is licensed under GPLv3+. Examples by me.)

I though miss the existence of an agrep subcommand. Guess why?

atool supports a wealth of archive types: tar (gzip-, bzip-, bzip2-, compress-/Z-, lzip-, lzop-, xz-, and 7zip-compressed), zip, jar/war, rar, lha/lzh, 7zip, alzip/alz, ace, ar, arj, arc, rpm, deb, cab, gzip, bzip, bzip2, compress/Z, lzip, lzop, xz, rzip, lrzip and cpio. (Not all subcommands support all archive types.)

Similar Utilities

There are some utilities which cover parts of what atool does, too:

Tools from the mtools package

Yes, they come from the “handle MS-DOS floppy disks tool” package, don’t ask me why. :-)

uz gunzip s and extracts a gzip ‘d tar ‘d archives Advantage over aunpack : Less to type. :-) Disadvantage compared to aunpack : Supports only one archive format. lz gunzip s and shows a listing of a gzip ‘d tar ‘d archive Advantage over als : One character less to type. :-) Disadvantage compared to als : Supports only one archive format.

unp extracts one or more files given as arguments on the command line.

$ unp -s Known archive formats and tools: 7z: p7zip or p7zip-full ace: unace ar,deb: binutils arj: arj bz2: bzip2 cab: cabextract chm: libchm-bin or archmage cpio,afio: cpio or afio dat: tnef dms: xdms exe: maybe orange or unzip or unrar or unarj or lha gz: gzip hqx: macutils lha,lzh: lha lz: lzip lzma: xz-utils or lzma lzo: lzop lzx: unlzx mbox: formail and mpack pmd: ppmd rar: rar or unrar or unrar-free rpm: rpm2cpio and cpio sea,sea.bin: macutils shar: sharutils tar: tar tar.bz2,tbz2: tar with bzip2 tar.lzip: tar with lzip tar.lzop,tzo: tar with lzop tar.xz,txz: tar with xz-utils tar.z: tar with compress tgz,tar.gz: tar with gzip uu: sharutils xz: xz-utils zip,cbz,cbr,jar,war,ear,xpi,adf: unzip zoo: zoo

So it’s very similar to aunpack , just a shorter command and it supports some more exotic archive formats which atool doesn’t support.

Also part of the unp package is ucat which does more or less the same as acat , just with unp as backend.

From the man page of dtrx :

In addition to providing one command to extract many different archive types, dtrx also aids the user by extracting contents consistently. By default, everything will be written to a dedicated directory that’s named after the archive. dtrx will also change the permissions to ensure that the owner can read and write all those files. Supported archive formats: tar, zip (including self-extracting .exe files), cpio, rpm, deb, gem, 7z, cab, rar, and InstallShield. It can also decompress files compressed with gzip, bzip2, lzma, or compress.

dtrx -l lists the contents of an archive, i.e. works like als or lz .

dtrx has two features not present in the other tools mentioned so far:

It can extract metadata instead of the normal contents from .deb and .gem files.

It can extract archives recursively, i.e. can extract archives inside of archives.

Unfortunately you can’t mix those two features. But you can use the following tool for that purpose:

deepfind

deepfind is a command from the package strigi-utils and recursively lists files in archives, including archives in archives. I’ve already written a detailed blog-posting about deepfind and its friend deepgrep.

tardiff was written to check what changed in source code tarballs from one release to another. By default it just lists the differences in the file lists, not in the files’ contents and hence works different than adiff .

atool and friends are probably the first choice when it comes to DWIM archive handling, also because they have an easy to remember subcommand scheme.

uz and lz and the shortest way to extract or list the contents of a .tar.gz file. But nothing more. And you have to install mtools even if you don’t have a floppy drive.

unp comes in handy for exotic archive formats atool doesn’t support. And it’s way easier to remember and type than aunpack .

dtrx is neat if you want to extract archives in archives or if you want to extract metadata from some package files with just a few keystrokes.