ar¶
Format: .a, .deb · Type: simple archiver · First released: early 1970s Unix
ar is one of the oldest Unix tools. It concatenates files with small headers and no compression. Today it's used for two things: static libraries (.a files full of object files) and the outer wrapper of Debian packages.
Basics¶
ar t archive.a # list members
ar tv archive.a # verbose list
ar x archive.a # extract all members
ar x archive.a foo.o # extract one member
ar rcs libfoo.a a.o b.o # create/replace members and write a symbol index
ar d archive.a foo.o # delete a member
For static libraries, nm libfoo.a shows the symbols and ranlib libfoo.a rebuilds the index (equivalent to ar s).
Unpacking a .deb¶
A .deb is an ar archive with three members:
| Member | Contents |
|---|---|
debian-binary |
Format version (2.0) |
control.tar.* |
Package metadata and maintainer scripts |
data.tar.* |
The files that get installed |
The inner tarballs may be gzip, xz or zstd depending on the distro and release.
ar t package.deb
ar x package.deb
tar xf data.tar.* -C extracted/ # tar auto-detects the compression
tar xf control.tar.* -C control/
# Or let dpkg do it
dpkg-deb -c package.deb # list files
dpkg-deb -I package.deb # show metadata
dpkg-deb -x package.deb extracted/ # extract files
dpkg-deb -e package.deb control/ # extract control files
What common package formats are made of¶
| Format | Under the hood | Unpack with |
|---|---|---|
.deb |
ar + tarballs | ar, dpkg-deb |
.rpm |
header + compressed cpio | rpm2cpio \| cpio -idmv |
.apk (Alpine) |
concatenated gzipped tars | tar xzf |
.apk (Android), .jar, .war, .whl, .docx, .xlsx, .odt, .epub |
zip | unzip |
.crate (Rust) |
gzipped tar | tar xzf |
.gem (Ruby) |
tar containing gzipped tars | tar xf, then tar xzf |
.snap |
SquashFS | unsquashfs |
.AppImage |
ELF runtime + SquashFS | ./app.AppImage --appimage-extract |
.iso |
ISO 9660 image | bsdtar xf, 7z x, or loop mount |
| OCI/Docker image layers | tar + gzip or zstd | skopeo, tar |