ar, ranlib(1) | manage archives |
ranlib, ar(1) | manage archives |
AR(1) | MidnightBSD General Commands Manual | AR(1) |
ar
, ranlib
— manage archives
ar |
-d [-T ]
[-f ] [-j ]
[-v ] [-z ]
archive file ... |
ar |
-m [-T ]
[-a position-after]
[-b position-before]
[-f ] [-i
position-before] [-j ]
[-s | -S ]
[-z ] archive
file ... |
ar |
-p [-T ]
[-f ] [-v ]
archive [file ...] |
ar |
-q [-T ]
[-c ] [-D ]
[-f ] [-s |
-S ] [-U ]
[-v ] [-z ]
archive file ... |
ar |
-r [-T ]
[-a position-after]
[-b position-before]
[-c ] [-D ]
[-f ] [-i
position-before] [-j ]
[-s | -S ]
[-u ] [-U ]
[-v ] [-z ]
archive file ... |
ar |
-s [-j ]
[-z ] archive |
ar |
-t [-f ]
[-T ] [-v ]
archive [file ...] |
ar |
-x [-C ]
[-T ] [-f ]
[-o ] [-u ]
[-v ] archive
[file ...] |
ar |
-M |
ranlib |
[-D ] [-U ]
archive ... |
The ar
utility creates and maintains
groups of files combined into an archive. Once an archive has been created,
new files can be added to it, and existing files can be extracted, deleted
or replaced.
Files are named in the archive by their last file name component, so if a file referenced by a path containing a “/” is archived, it will be named by the last component of the path. Similarly when matching paths listed on the command line against file names stored in the archive, only the last component of the path will be compared.
The normal use of ar
is for the creation
and maintenance of libraries suitable for use with the link editor
ld(1), although it is not
restricted to this purpose. The ar
utility can
create and manage an archive symbol table (see
ar(5)) used to speed up link
editing operations. If a symbol table is present in an archive, it will be
kept up-to-date by subsequent operations on the archive.
The ranlib
utility is used to add an
archive symbol table to an existing archive.
The ar
utility supports the following
options:
-a
member-after-m
this option specifies
that the archive members specified by arguments file
... are moved to after the archive member named by argument
member-after. When used with option
-r
this option specifies that the files specified
by arguments file ... are added after the archive
member named by argument member-after.-b
member-before-m
this option specifies
that the archive members specified by arguments file
... are moved to before the archive member named by argument
member-before. When used with option
-r
this option specifies that the files specified
by arguments file ... are added before the archive
member named by argument member-before.-c
-r
and -q
options.-C
-d
-D
-r
or
-q
option, with the -s
option without other options, or when invoked as
ranlib
, insert 0's instead of the real mtime, uid
and gid values and 0644 instead of file mode from the members named by
arguments file .... This ensures that checksums on
the resulting archives are reproducible when member contents are
identical. This option is enabled by default. If multiple
-D
and -U
options are
specified on the command line, the final one takes precedence.-f
-i
member-before-b
.-j
-l
-m
-a
, -b
or
-i
options, the members are moved to before or
after the specified position. If no position has been specified, the
specified members are moved to the end of the archive. If the archive has
a symbol table, it is updated to reflect the new contents of the
archive.-M
ar
utility are described in the
section MRI Librarian
Commands.-o
-p
-q
-r
-a
, -b
or -i
is specified. The archive symbol table, if
it exists, is updated to reflect the new state of the archive.-s
ar
with the -s
option
alone is equivalent to invoking ranlib
.-S
-t
-T
-f
. In other implementations
of ar
, -T
creates a
"thin" archive.-u
-r
option, files named by arguments
file ... will be replaced in the archive if they are
newer than their archived versions. When used with the
-x
option, the members specified by arguments
file ... will be extracted only if they are newer
than the corresponding files in the file system.-U
-r
or
-q
option, insert the real mtime, uid and gid, and
file mode values from the members named by arguments file
.... If multiple -D
and
-U
options are specified on the command line, the
final one takes precedence.-v
-d
,
-m
, -q
or
-x
options, ar
gives a
file-by-file description of the archive modification being performed,
which consists of three white-space separated fields: the option letter, a
dash “-”, and the file name. When used with the
-r
option, ar
displays the
description as above, but the initial letter is an “a” if
the file is added to the archive, or an “r” if the file
replaces a file already in the archive. When used with the
-p
option, the name of the file enclosed in
“<” and “>” characters is written to
standard output preceded by a single newline character and followed by two
newline characters. The contents of the named file follow the file name.
When used with the -t
option,
ar
displays eight whitespace separated fields: the
file permissions as displayed by
strmode(3), decimal
user and group IDs separated by a slash ( “/”),the file size
in bytes, the file modification time in
strftime(3) format
“%b %e %H:%M %Y”, and the name of the file.-V
-x
-o
option was specified.-z
If the -M
option is specified, the
ar
utility will read and execute commands from its
standard input. If standard input is a terminal, the
ar
utility will display the prompt
“AR >
” before reading a line, and
will continue operation even if errors are encountered. If standard input is
not a terminal, the ar
utility will not display a
prompt and will terminate execution on encountering an error.
Each input line contains a single command. Words in an input line are separated by whitespace characters. The first word of the line is the command, the remaining words are the arguments to the command. The command word may be specified in either case. Arguments may be separated by commas or blanks.
Empty lines are allowed and are ignored. Long lines are continued
by ending them with the “+
”
character.
The “*
” and
“;
” characters start a comment.
Comments extend till the end of the line.
When executing an MRI librarian script the
ar
utility works on a temporary copy of an archive.
Changes to the copy are made permanent using the
save
command.
Commands understood by the ar
utility
are:
addlib
archive |
addlib
archive (member [,
member]...)addmod
member [, member]...clear
create
archivesave
command is
issued.delete
module [, member]...directory
archive (member [,
member]...) [outputfile]verbose
command. Output is sent to standard output, or to the file specified by
argument outputfile.end
ar
utility. Any unsaved
changes to the current archive will be discarded.extract
member [, member]...list
open
archivereplace
member [, member]...save
verbose
directory
command.To create a new archive ex.a containing three files ex1.o, ex2.o and ex3.o, use:
ar -rc ex.a ex1.o ex2.o
ex3.o
To add an archive symbol table to an existing archive ex.a, use:
ar -s ex.a
To delete file ex1.o from archive ex.a, use:
To verbosely list the contents of archive ex.a, use:
To create a new archive ex.a containing the files ex1.o, and ex2.o, using MRI librarian commands, use the following script:
create ex.a * specify the output archive addmod ex1.o ex2.o * add modules save * save pending changes end * exit the utility
The ar
utility exits 0 on success,
and >0 if an error occurs.
The ar
utility's support for the
-a
, -b
,
-c
, -i
,
-m
, -p
,
-q
, -r
,
-s
, -t
,
-u
, -v
,
-C
and -T
options is
believed to be compliant with IEEE Std 1003.2
(“POSIX.2”).
An ar
command first appeared in AT&T
UNIX Version 1. In FreeBSD 8.0, Kai
Wang
<kaiw@FreeBSD.org>
reimplemented ar
and ranlib
using the Streaming Archive Library (libarchive,
-larchive) and the ELF Access Library (libelf,
-lelf).
December 29, 2021 | midnightbsd-3.1 |