1AR(P)                      POSIX Programmer's Manual                     AR(P)
2
3
4

NAME

6       ar - create and maintain library archives
7

SYNOPSIS

9       ar -d[-v] archive file ...
10
11
12
13       ar -m [-v] archive file ...
14
15       ar -m -a[-v] posname archive file ...
16
17       ar -m -b[-v] posname archive file ...
18
19       ar -m -i[-v] posname archive file ...
20
21       ar -p[-v][-s]archive [file ...]
22
23
24
25       ar -q[-cv] archive file ...
26
27       ar -r[-cuv] archive file ...
28
29
30
31       ar -r -a[-cuv] posname archive file ...
32
33       ar -r -b[-cuv] posname archive file ...
34
35       ar -r -i[-cuv] posname archive file ...
36
37       ar -t[-v][-s]archive [file ...]
38
39       ar -x[-v][-sCT]archive [file ...]
40
41

DESCRIPTION

43       The ar utility is part of the Software Development Utilities option.
44
45       The  ar utility can be used to create and maintain groups of files com‐
46       bined into an archive. Once an archive has been created, new files  can
47       be  added,  and existing files in an archive can be extracted, deleted,
48       or replaced. When an archive consists entirely of valid  object  files,
49       the  implementation  shall format the archive so that it is usable as a
50       library for link editing  (see  c99  and  fort77).  When  some  of  the
51       archived  files  are not valid object files, the suitability of the ar‐
52       chive for library use is undefined.    If an archive consists  entirely
53       of printable files, the entire archive shall be printable.
54
55       When ar creates an archive, it creates administrative information indi‐
56       cating whether a symbol table is present in the archive. When there  is
57       at  least one object file that ar recognizes as such in the archive, an
58       archive symbol table shall be created in the archive and maintained  by
59       ar;  it  is used by the link editor to search the archive. Whenever the
60       ar utility is used to create or update the contents of such an archive,
61       the symbol table shall be rebuilt. The -s option shall force the symbol
62       table to be rebuilt.
63
64       All file operands can be  pathnames.  However,  files  within  archives
65       shall  be named by a filename, which is the last component of the path‐
66       name used when the file was entered into the archive. The comparison of
67       file  operands  to the names of files in archives shall be performed by
68       comparing the last component of the operand to the name of the file  in
69       the archive.
70
71       It  is unspecified whether multiple files in the archive may be identi‐
72       cally named. In the case of such files, however, each file    and  pos‐
73       name   operand  shall match only the first file in the archive having a
74       name that is the same as the last component of the operand.
75

OPTIONS

77       The ar  utility  shall  conform  to  the  Base  Definitions  volume  of
78       IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
79
80       The following options shall be supported:
81
82       -a     Position  new  files  in the archive after the file named by the
83              posname operand.
84
85       -b     Position new files in the archive before the file named  by  the
86              posname operand.
87
88       -c     Suppress  the  diagnostic  message  that  is written to standard
89              error by default when the archive archive is created.
90
91       -C     Prevent extracted files from replacing like-named files  in  the
92              file system. This option is useful when -T is also used, to pre‐
93              vent truncated filenames from replacing files with the same pre‐
94              fix.
95
96       -d     Delete one or more files from archive.
97
98       -i     Position new files in the archive before the file in the archive
99              named by the posname operand (equivalent to -b).
100
101       -m     Move the named files in the archive. The -a, -b, or  -i  options
102              with  the posname operand indicate the position; otherwise, move
103              the names files in the archive to the end of the archive.
104
105       -p     Write the contents of the files in the archive named by file op‐
106              erands from archive to the standard output.  If no file operands
107              are specified, the contents of all files in the archive shall be
108              written in the order of the archive.
109
110       -q     Append  the  named files to the end of the archive. In this case
111              ar does not check whether the added files are already in the ar‐
112              chive.  This  is  useful  to bypass the searching otherwise done
113              when creating a large archive piece by piece.
114
115       -r     Replace or add files to archive. If the archive named by archive
116              does  not exist, a new archive shall be created and a diagnostic
117              message shall be written to standard error (unless the -c option
118              is specified). If no files are specified and the archive exists,
119              the results are undefined.  Files that replace existing files in
120              the  archive  shall  not  change the order of the archive. Files
121              that do not replace existing  files  in  the  archive  shall  be
122              appended  to the archive    unless a -a, -b, or -i option speci‐
123              fies another position.
124
125       -s     Force the regeneration of the archive symbol table even if ar is
126              not  invoked  with an option that modifies the archive contents.
127              This option is useful to restore the archive symbol table  after
128              it has been stripped; see strip.
129
130       -t     Write  a  table  of  contents of archive to the standard output.
131              The files specified by the file operands shall  be  included  in
132              the  written  list. If no file operands are specified, all files
133              in archive shall be included in the order of the archive.
134
135       -T     Allow filename truncation of extracted files whose archive names
136              are  longer  than  the  file  system  can  support.  By default,
137              extracting a file with a name that  is  too  long  shall  be  an
138              error;  a diagnostic message shall be written and the file shall
139              not be extracted.
140
141       -u     Update older files in the archive. When used with the -r option,
142              files in the archive shall be replaced only if the corresponding
143              file has a modification time that is at least as new as the mod‐
144              ification time of the file in the archive.
145
146       -v     Give  verbose  output.  When used with the option characters -d,
147              -r, or -x, write a detailed file-by-file description of the  ar‐
148              chive  creation  and  maintenance  activity, as described in the
149              STDOUT section.
150
151       When used with -p, write the name of the file in  the  archive  to  the
152       standard  output  before  writing the file in the archive itself to the
153       standard output, as described in the STDOUT section.
154
155       When used with -t, include a long  listing  of  information  about  the
156       files in the archive, as described in the STDOUT section.
157
158       -x     Extract the files in the archive named by the file operands from
159              archive. The contents of the archive shall not be changed. If no
160              file  operands  are  given,  all  files  in the archive shall be
161              extracted. The modification time of each file extracted shall be
162              set to the time the file is extracted from the archive.
163
164

OPERANDS

166       The following operands shall be supported:
167
168       archive
169              A pathname of the archive.
170
171       file   A pathname. Only the last component shall be used when comparing
172              against the names of files in the archive. If two or  more  file
173              operands  have  the same last pathname component (basename), the
174              results are unspecified.  The  implementation's  archive  format
175              shall not truncate valid filenames of files added to or replaced
176              in the archive.
177
178       posname
179              The name of a file in the archive, used for  relative  position‐
180              ing; see options -m and -r.
181
182

STDIN

184       Not used.
185

INPUT FILES

187       The  archive  named by archive shall be a file in the format created by
188       ar -r.
189

ENVIRONMENT VARIABLES

191       The following environment variables shall affect the execution of ar:
192
193       LANG   Provide a default value for the  internationalization  variables
194              that  are  unset  or  null.  (See the Base Definitions volume of
195              IEEE Std 1003.1-2001, Section  8.2,  Internationalization  Vari‐
196              ables  for the precedence of internationalization variables used
197              to determine the values of locale categories.)
198
199       LC_ALL If set to a non-empty string value, override the values  of  all
200              the other internationalization variables.
201
202       LC_CTYPE
203              Determine  the  locale  for  the  interpretation of sequences of
204              bytes of text data as characters (for  example,  single-byte  as
205              opposed to multi-byte characters in arguments and input files).
206
207       LC_MESSAGES
208              Determine  the  locale  that should be used to affect the format
209              and contents of diagnostic messages written to standard error.
210
211       LC_TIME
212              Determine the format and content for date and time strings writ‐
213              ten by ar -tv.
214
215       NLSPATH
216              Determine the location of message catalogs for the processing of
217              LC_MESSAGES .
218
219       TMPDIR Determine the pathname that overrides the default directory  for
220              temporary files, if any.
221
222       TZ     Determine  the  timezone used to calculate date and time strings
223              written by ar -tv. If  TZ  is  unset  or  null,  an  unspecified
224              default timezone shall be used.
225
226

ASYNCHRONOUS EVENTS

228       Default.
229

STDOUT

231       If the -d option is used with the -v option, the standard output format
232       shall be:
233
234
235              "d - %s\n", <file>
236
237       where file is the operand specified on the command line.
238
239       If the -p option is used with the -v option, ar shall precede the  con‐
240       tents of each file with:
241
242
243              "\n<%s>\n\n", <file>
244
245       where  file is the operand specified on the command line, if file oper‐
246       ands were specified, and the name of the file in the  archive  if  they
247       were not.
248
249       If the -r option is used with the -v option:
250
251        * If  file is already in the archive, the standard output format shall
252          be:
253
254
255          "r - %s\n", <file>
256
257       where <file> is the operand specified on the command line.
258
259        * If file is not already in the archive, the  standard  output  format
260          shall be:
261
262
263          "a - %s\n", <file>
264
265       where <file> is the operand specified on the command line.
266
267       If  the -t option is used, ar shall write the names of the files in the
268       archive to the standard output in the format:
269
270
271              "%s\n", <file>
272
273       where file is the operand specified on the command line, if file  oper‐
274       ands  were  specified,  or  the name of the file in the archive if they
275       were not.
276
277       If the -t option is used with the -v option, the standard output format
278       shall be:
279
280
281              "%s %u/%u %u %s %d %d:%d %d %s\n", <member mode>, <user ID>,
282                  <group ID>, <number of bytes in member>,
283                  <abbreviated month>, <day-of-month>, <hour>,
284                  <minute>, <year>, <file>
285
286       where:
287
288       <file> Shall  be the operand specified on the command line, if file op‐
289              erands were specified, or the name of the file in the archive if
290              they were not.
291
292       <member mode>
293
294              Shall be formatted the same as the <file mode> string defined in
295              the STDOUT section of ls, except that the first  character,  the
296              <entry type>,  is  not used; the string represents the file mode
297              of the file in the archive at  the  time  it  was  added  to  or
298              replaced in the archive.
299
300
301       The  following  represent  the last-modification time of a file when it
302       was most recently added to or replaced in the archive:
303
304       <abbreviated month>
305
306              Equivalent to the format of the %b conversion specification for‐
307              mat in date.
308
309       <day-of-month>
310
311              Equivalent to the format of the %e conversion specification for‐
312              mat in date.
313
314       <hour> Equivalent to the format of the %H conversion specification for‐
315              mat in date.
316
317       <minute>
318              Equivalent to the format of the %M conversion specification for‐
319              mat in date.
320
321       <year> Equivalent to the format of the %Y conversion specification for‐
322              mat in date.
323
324
325       When  LC_TIME does not specify the POSIX locale, a different format and
326       order of presentation of these fields relative to  each  other  may  be
327       used in a format appropriate in the specified locale.
328
329       If the -x option is used with the -v option, the standard output format
330       shall be:
331
332
333              "x - %s\n", <file>
334
335       where file is the operand specified on the command line, if file  oper‐
336       ands  were  specified,  or  the name of the file in the archive if they
337       were not.
338

STDERR

340       The standard error shall be used  only  for  diagnostic  messages.  The
341       diagnostic  message  about creating a new archive when -c is not speci‐
342       fied shall not modify the exit status.
343

OUTPUT FILES

345       Archives are files with unspecified formats.
346

EXTENDED DESCRIPTION

348       None.
349

EXIT STATUS

351       The following exit values shall be returned:
352
353        0     Successful completion.
354
355       >0     An error occurred.
356
357

CONSEQUENCES OF ERRORS

359       Default.
360
361       The following sections are informative.
362

APPLICATION USAGE

364       None.
365

EXAMPLES

367       None.
368

RATIONALE

370       The archive format is not described. It is recognized  that  there  are
371       several  known ar formats, which are not compatible.  The ar utility is
372       included, however, to allow creation of archives that are intended  for
373       use only on one machine. The archive is specified as a file, and it can
374       be moved as a file. This does allow an archive to  be  moved  from  one
375       machine to another machine that uses the same implementation of ar.
376
377       Utilities  such  as  pax  (and its forebears tar and cpio) also provide
378       portable "archives". This is a not a duplication;  the  ar  utility  is
379       included  to provide an interface primarily for make and the compilers,
380       based on a historical model.
381
382       In historical implementations, the -q option (available on XSI-conform‐
383       ing  systems)  is known to execute quickly because ar does not check on
384       whether the added members are already in the archive. This is useful to
385       bypass  the  searching  otherwise  done  when  creating a large archive
386       piece-by-piece. These remarks may but need not remain true for a  brand
387       new  implementation  of  this  utility;  hence, these remarks have been
388       moved into the RATIONALE.
389
390       BSD implementations historically required applications to  provide  the
391       -s  option whenever the archive was supposed to contain a symbol table.
392       As in this volume of IEEE Std 1003.1-2001, System V  historically  cre‐
393       ates  or  updates  an  archive  symbol table whenever an object file is
394       removed from, added to, or updated in the archive.
395
396       The OPERANDS section requires what might seem to be true without speci‐
397       fying  it:  the archive cannot truncate the filenames below {NAME_MAX}.
398       Some historical implementations  do  so,  however,  causing  unexpected
399       results    for    the    application.   Therefore,   this   volume   of
400       IEEE Std 1003.1-2001 makes the requirement explicit to avoid  misunder‐
401       standings.
402
403       According  to  the System V documentation, the options -dmpqrtx are not
404       required  to  begin  with  a  hyphen  (  '-'   ).    This   volume   of
405       IEEE Std 1003.1-2001  requires  that  a  conforming application use the
406       leading hyphen.
407
408       The archive format used by the 4.4 BSD implementation is documented  in
409       this  RATIONALE  as  an  example:  A file created by ar begins with the
410       "magic" string "!<arch>\n" . The rest of the  archive  is  made  up  of
411       objects,  each  of which is composed of a header for a file, a possible
412       filename, and the file contents. The header is portable between machine
413       architectures,  and, if the file contents are printable, the archive is
414       itself printable.
415
416       The header is made up of six ASCII fields, followed by a  two-character
417       trailer.  The fields are the object name (16 characters), the file last
418       modification time (12 characters), the user and group IDs (each 6 char‐
419       acters),  the  file  mode (8 characters), and the file size (10 charac‐
420       ters). All numeric fields are in decimal, except  for  the  file  mode,
421       which is in octal.
422
423       The  modification  time  is the file st_mtime field. The user and group
424       IDs are the file st_uid and st_gid fields. The file mode  is  the  file
425       st_mode  field.  The  file size is the file st_size field. The two-byte
426       trailer is the string "`<newline>" .
427
428       Only the name field has any provision for overflow. If any filename  is
429       more  than  16  characters in length or contains an embedded space, the
430       string "#1/" followed by the ASCII length of the name is written in the
431       name field. The file size (stored in the archive header) is incremented
432       by the length of the name. The name is then written immediately follow‐
433       ing the archive header.
434
435       Any  unused  characters in any of these fields are written as <space>s.
436       If any fields are their particular  maximum  number  of  characters  in
437       length, there is no separation between the fields.
438
439       Objects  in  the archive are always an even number of bytes long; files
440       that are an odd number of bytes  long  are  padded  with  a  <newline>,
441       although the size in the header does not reflect this.
442
443       The  ar  utility  description  requires  that (when all its members are
444       valid object files) ar produce an object code library, which the  link‐
445       age  editor  can  use to extract object modules.  If the linkage editor
446       needs a symbol table to permit random access to the  archive,  ar  must
447       provide it; however, ar does not require a symbol table.
448
449       The BSD -o option was omitted. It is a rare conforming application that
450       uses ar to extract object code from a library with concern for its mod‐
451       ification  time,  since  this can only be of importance to make. Hence,
452       since this functionality  is  not  deemed  important  for  applications
453       portability, the modification time of the extracted files is set to the
454       current time.
455
456       There is at least one known implementation (for a small computer)  that
457       can  accommodate  only  object files for that system, disallowing mixed
458       object and other files. The ability to handle any type of file  is  not
459       only  historical  practice for most implementations, but is also a rea‐
460       sonable expectation.
461
462       Consideration was given to changing the output format of ar -tv to  the
463       same  format  as  the output of ls -l. This would have made parsing the
464       output of ar the same as that of ls. This was rejected in part  because
465       the current ar format is commonly used and changes would break histori‐
466       cal usage. Second, ar gives the user ID and group ID in numeric  format
467       separated  by a slash. Changing this to be the user name and group name
468       would not be correct if the archive were moved to a machine  that  con‐
469       tained  a different user database. Since ar cannot know whether the ar‐
470       chive was generated on the same machine, it cannot tell what to report.
471
472       The text on the -ur option combination is historical practice-since one
473       filename  can easily represent two different files (for example, /a/foo
474       and /b/foo), it is reasonable to replace the file in the  archive  even
475       when  the  modification time in the archive is identical to that in the
476       file system.
477

FUTURE DIRECTIONS

479       None.
480

SEE ALSO

482       c99 , date , fort77 , pax  ,  strip  the  Base  Definitions  volume  of
483       IEEE Std 1003.1-2001,  Chapter  13,  Headers, <unistd.h> description of
484       {POSIX_NO_TRUNC}
485
487       Portions of this text are reprinted and reproduced in  electronic  form
488       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
489       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
490       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
491       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
492       event of any discrepancy between this version and the original IEEE and
493       The Open Group Standard, the original IEEE and The Open Group  Standard
494       is  the  referee document. The original Standard can be obtained online
495       at http://www.opengroup.org/unix/online.html .
496
497
498
499IEEE/The Open Group                  2003                                AR(P)
Impressum