ar (Unix)

from Wikipedia, the free encyclopedia

ar (from English archiver ) is a Unix command that can compress several files into a single archive file. It is mainly used nowadays to generate static libraries that can be passed to a linker . Since it is a classic archiving program , it can also be used for any other purpose, but has now been replaced by the much more powerful tar .

ar is standardized by the Single UNIX Specification . The implementation of the GNU project is part of the GNU Binutils .

use

ar is Unix mainly for static libraries used with such an archive multiple object files containing that when left to be integrated into this one program. Also Debian package format .deb based on ar. In principle, ar can also be used as a normal program for archiving, although you have to accept some restrictions, which are explained in the section on file format .

Example calls

There are different ar variants, which means that the following examples, tested with Darwin's ar, may have to be slightly modified for other operating systems.

ar -q archiv.a datei1 datei2

With this command, if the file does not yet exist, the archive archiv.a is created and filled with the files file1 and file2, whereby no path information is stored in the file.

ar -x archiv.a

The command to unzip.

% ar -t archive.a
datei1
datei2

If you want to see which files are contained in the archive, you call ar with the parameter -t.

% ar -tv archive.a
rw-r--r--     UID/GID       BYTES Feb  9 19:21 2006 datei1
rw-r--r--     UID/GID       BYTES Feb  9 19:22 2006 datei2

The parameter -v stands for verbose and with -t causes an output similar to ls :

UID are the user ID, the numerical representations of the user names, GID are the group ID under which the files were created and BYTES are the file sizes.

File format

The file format used by ar is not standardized, which is why there may be some incompatible variants. BSD-ar is described below:

ar files begin with the magic number !<arch>\n , where \na line feed represents, followed by the archived files with header. The header is in one line in front of the respective file content, which contains the metadata file name (16 characters), last access time as Unix time stamp (12 characters), user and group ID (6 characters each), file access rights (8 characters) and contains the file size (10 characters); this structure can also be found in the header file /usr/include/ar.h. In case of doubt, all data records are padded with spaces in order to achieve the specified lengths. If the file is an odd number of bytes, a line feed is inserted as the last character for padding.

The field that contains the file name is the only way to deal with longer values: If the file name is too long, this field contains the string #1/followed by the actual length of the file name, which is then on the following line.

The file content is terminated by a line feed, which is possibly followed by the header of the next file.

restrictions

  • ar saves files without their path, so an ordner/unter/dateiarchived file is datei extracted later than in the current directory.
  • With the limitation of the field for the file size to 10 characters, no files with more than 10 GB minus 1 byte (≈9.31 GiB ) can be saved.

Web links