ArticleslgStudy

computer science

Ar (Unix)

Ar (Unix) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Ar (Unix) rather than just read about it. In short: ar, short for archiver, is a shell command for maintaining multiple files as a single archive file (i.e. a file archiver). It is often used to create and update static library files that the link editor or linker uses and for generating deb format packages for the Debian Linux distribution.

Ar (Unix) — main illustration
Ar (Unix) — illustration

Key takeaways

  • Ar (Unix) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Ar (Unix) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Ar (Unix) from memory before moving on to harder problems.

Reference excerpt

ar, short for archiver, is a shell command for maintaining multiple files as a single archive file (i.e. a file archiver). It is often used to create and update static library files that the link editor or linker uses and for generating deb format packages for the Debian Linux distribution. It can be used to create archives for any purpose, but has been largely replaced by tar for purposes other than static libraries. Originally developed for Unix, the command is widely available on Unix-based systems, and similar commands are available on other platforms. An implementation is included in GNU Binutils.

File format

The format of a file that results from using ar has never been standardized, though most variations were documented through the manual page ar(5) or at least the header file ar.h.

The first format appeared in the first edition of Unix and was used through Version 6 Unix. It had a magic number of ED FF (0177555). Version 7 Unix had a modified version of that format, which was also used in UNIX System III and in UNIX System V on the PDP-11. A new format was introduced in the first release of System V on processors other than PDP-11s. This format had a magic number of 0177545. Modern archives are, on most systems, based on a common format with two main variants, BSD (initially used for a.out files) and UNIX System V release 2 and later (initially used for COFF files and later used for ELF files) and used as well by GNU and Windows. AIX has its own formats (small and big), as does Coherent; those formats vary significantly from the common format. In addition to the usual per-entry header, AIX formats include a global header that together enables handling the archive as a doubly-linked list.

Structure An archive file begins with a header that identifies the file type and is followed with a section for each contained file. Each contained file section consists of a header followed by the file content. The headers consist solely of printable ASCII characters and line feeds. In fact, an archive containing only text files is also a text file. The content of a contained file begins on an even byte boundary. A newline is inserted between files as padding, if necessary. Nevertheless, the size stored reflects the size excluding padding.

Archive header The first header, a.k.a. file signature, is a magic number that encodes the ASCII string !<arch> followed by a single line feed character (0x0A).

Contained file header Each file is preceded by a header that contains information about the file. The common format is as follows. Numeric values are encoded in ASCII and all values are right-padded with spaces (0x20).

Variants Variants of the command were developed to address issues including:

File name length limitation The BSD and System V/GNU variants devised different methods of storing long or "extended" file names (beyond the 15 or 16-character limit). Global symbol table Many implementations include a global symbol table (a.k.a. armap, directory or index) for fast linking without needing to scan the whole archive for a symbol. POSIX recognizes this feature, and requires implementations to have an -s option for updating it. Most implementations put it at the first file entry. Year 2038 problem Although the common format is not at risk of this problem, many implementations are vulnerable to failure in that year due to how they parse the time entry. The entry itself would max out at 999,999,999,999, which would imply to a much later year-33658 problem.

BSD With the standard name field, the 4.0BSD implementation stores file names right-padded with ASCII spaces (0x20). Only file names that are up to 16 bytes long and contains no spaces are put in the standard field. For all other file names, it places the string "#1/" followed by the file name length (decimal) in the standard name field, then stores the real file name in front of the data section. The BSD implementation traditionally does not handle the building of a global symbol lookup table, and delegates this task to a separate utility, ranlib, which inserts an architecture-specific file named __.SYMDEF as first archive member. Some descendants put a space and "SORTED" after the name to indicate a sorted version. A 64-bit variant called __.SYMDEF_64 exists on Darwin. To conform to POSIX, newer BSD implementations support the -s option instead of ranlib. FreeBSD in particular ditched the SYMDEF table format and embraced the System V style table.

SysV/GNU To allow spaces in file names, the System V Revision 2 (SVR2) implementation uses a slash ('/') to mark the end of the file. This limits the file name to 15 chars. Filenames longer than 15 ASCII chars are replaced by an index, represented by a slash ('/') followed by the decimal character offset in the indexfile (also called the "archive stream table), pointing to the location of the start of the name (for example, /768 refers to a name that starts at offset 768 in the index file.) Adopted by many non-BSD Unixes and GNU, this format is called "SVR4/GNU" by BSD documentations. The index file is named // and is usually the second entry of the archive, after the symbol table which always is the first. The format of this // file itself is simply a list of the long file names, separated by the sequence /\n LF (0x2F 0x10). The SVR4/GNU format uses the special file name "/" to denote that the following data entry contains a symbol lookup table, which is used in ar libraries to speed up access. This symbol table is built in three parts which are recorded together as contiguous data.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Ar (Unix)

Start with the simplest possible case. Write down what Ar (Unix) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Ar (Unix) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Ar (Unix) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Ar (Unix)

In research
Ar (Unix) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Ar (Unix) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Ar (Unix) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Archive formats, File archivers, GNU Project software, so understanding it makes those chapters shorter.
In everyday life
Look for Ar (Unix) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Ar (Unix)” →

How to study Ar (Unix) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Ar (Unix) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Ar (Unix) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Ar (Unix) in simple terms?

ar, short for archiver, is a shell command for maintaining multiple files as a single archive file (i.e. a file archiver). It is often used to create and update static library files that the link editor or linker uses and for generating deb format packages for the Debian Linux distribution.

Why does Ar (Unix) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Ar (Unix)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Ar (Unix).

Tags

  • Archive formats
  • File archivers
  • GNU Project software
  • Inferno (operating system) commands
  • Plan 9 commands
  • Standard Unix programs
  • Unix SUS2008 utilities
  • Unix archivers and compression-related utilities
  • Unix programming tools

Keep exploring