ar (Unix)

Ar (of English. archiver ) is a Unix command that can pack up multiple files into a single archive file. Today, it is mainly used to generate static libraries that can be passed to a linker. Since this is a classic archiving program, it can also be used for any other purpose, but its 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 mainly used on Unix for static libraries, where such an archive contains several object files that are included when linking a program in this. Also based Debian package format. Deb on ar. Principle, one can ar also use as a normal program for archiving, it being necessary to take some limitations into account, which are explained in the section file format.

Example calls

There are different ar variants, which of the following examples, tested with Darwin ar, for other operating systems have to be easily modified under certain circumstances.

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

Ar -x archiv.a The command to unpack.

% Ar -t archive.a file1 file2 Would you look at what files are included in the archive, you call ar on with the -t parameter.

% Ar -tv archive.a rw- r - r - UID / GID BYTES February 9 2006 19:21 file1 rw- r - r - UID / GID BYTES February 9 2006 19:22 file2 The - v option stands for verbose and causes with -t a ls -like output:

UID are the user ID, the numerical representations of the user name, GID is 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, so there may be some mutually incompatible versions. Below is BSD -ar described:

Ar files begin with the magic number! \ n where \ n represents a newline character followed by the archived files with headers. The header stands in a row of each file content, the metadata file name (16 characters), last access time as a Unix timestamp (12 characters), User and group ID ( 6 figures ), file permissions (8 characters ) and the file size (10 characters) contains; this structure can also be found in the header file / usr / include / ar.h. All records are filled in doubt, use spaces to achieve the stated lengths. If the file has an odd number of bytes is large, a line feed is inserted to fill up as the last character.

The field that contains the file name, the only offers a 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 available in the following line.

The file contents is terminated by a newline, followed, if necessary, the header of the next file follows.

Limitations

  • Ar stores files without from their path, consequently, as a folder / archived under / file file is later extracted as a file in the current directory.
  • With the limitation of the field for the file size to 10 characters can not send files with more than 10 GB minus 1 byte ( ≈ 9:31 GiB ) are stored.
4249
de