ar

Create or modify a backup file, or extract files from a backup file

Supplementary instructions

ar command is a tool for creating or modifying backup files, or extracting files from backup files. ar allows you to combine many files into a single backup file. In the saved file, all member files retain their original attributes and permissions.

grammar

Usage: ar [emulation options] [-]{dmpqrstx}[abcDfilMNoOPsSTuvV] [--plugin <name>] [member-name] [count] archive-file file...
       ar -M [<mri-script]

Options

The following content is from GNU ar (GNU Binutils) version 2.40 instructions
Order:
       d - delete files from archive
       m[ab] - move files within an archive
       p - Print files found in the archive
       q[f] - Quickly append a file to the archive
       r[ab][f][u] - replace existing files in the archive or add new files
       s - works as ranlib
       t[O][v] - display contents of the archive
       x[o] - explode files from archive
Specific command modifiers:
       [a] - Place file after [member name]
       [b] - Place file before [member name] (same as [i])
       [D] - Use 0 for timestamp and uid/gid (default)
       [D] - use actual timestamp and uid/gid
       [N] - Instances using name [number]
       [f] - truncate inserted file name
       [P] - use full pathname when matching
       [o] - keep the original date
       [O] - display offsets of files in the archive
       [u] - Replace only files newer than the current archive contents
Common modifiers:
       [c] - Don't give a warning when a library must be created
       [s] - Create archive index (cf. ranlib)
       [l <text> ] - specify the dependencies of this library
       [S] - Do not create a symbol table
       [T] - deprecated, use --thin instead
       [v] - output more information
       [V] - Display version number
       @<file> - read options from <file>
       --target=BFDNAME - Specify target object format as BFDNAME
       --output=DIRNAME - specify the output directory for extraction operations
       --record-libdeps=<text> - specify the dependencies of this library
       --thin - make a thin archive
Options:
       --plugin <p> - load the specified plug-in
Simulation options:
       No emulation-specific options

Example

Package file

[root@localhost ~]# ls # Display files in the current directory
a.c b.c d.c install.log qte
anaconda-ks.cfg c.c Desktop

[root@localhost ~]# ar rv one.bak a.c b.c # Package a.c b.c files
ar: Creating one.bak
a-a.c
a-b.c

Pack multiple files

[root@localhost ~]# ar rv two.bak *.c // Pack files ending with .c
ar: creating two.bak
a-a.c
a-b.c
a-c.c
a-d.c

Display the contents of the packaged file

[root@localhost ~]# ar t two.bak
a.c
b.c.
c.c.
d.c

Delete member files of packaged files

[root@localhost ~]# ar d two.bak a.c b.c c.c
[root@localhost ~]# ar t two.bak
d.c