1.\" Copyright (c) 2007,2009-2012 Joseph Koshy. All rights reserved. 2.\" 3.\" Redistribution and use in source and binary forms, with or without 4.\" modification, are permitted provided that the following conditions 5.\" are met: 6.\" 1. Redistributions of source code must retain the above copyright 7.\" notice, this list of conditions and the following disclaimer. 8.\" 2. Redistributions in binary form must reproduce the above copyright 9.\" notice, this list of conditions and the following disclaimer in the 10.\" documentation and/or other materials provided with the distribution. 11.\" 12.\" This software is provided by Joseph Koshy ``as is'' and 13.\" any express or implied warranties, including, but not limited to, the 14.\" implied warranties of merchantability and fitness for a particular purpose 15.\" are disclaimed. in no event shall Joseph Koshy be liable 16.\" for any direct, indirect, incidental, special, exemplary, or consequential 17.\" damages (including, but not limited to, procurement of substitute goods 18.\" or services; loss of use, data, or profits; or business interruption) 19.\" however caused and on any theory of liability, whether in contract, strict 20.\" liability, or tort (including negligence or otherwise) arising in any way 21.\" out of the use of this software, even if advised of the possibility of 22.\" such damage. 23.\" 24.\" $Id: ar.1 3195 2015-05-12 17:22:19Z emaste $ 25.\" 26.Dd December 10, 2012 27.Os 28.Dt AR 1 29.Sh NAME 30.Nm ar 31.Nd manage archives 32.Sh SYNOPSIS 33.Nm 34.Fl d 35.Op Fl T 36.Op Fl f 37.Op Fl j 38.Op Fl v 39.Op Fl z 40.Ar archive 41.Ar 42.Nm 43.Fl m 44.Op Fl T 45.Op Fl a Ar position-after 46.Op Fl b Ar position-before 47.Op Fl f 48.Op Fl i Ar position-before 49.Op Fl j 50.Op Fl s | Fl S 51.Op Fl z 52.Ar archive 53.Ar 54.Nm 55.Fl p 56.Op Fl T 57.Op Fl f 58.Op Fl v 59.Ar archive 60.Op Ar 61.Nm 62.Fl q 63.Op Fl T 64.Op Fl c 65.Op Fl D 66.Op Fl f 67.Op Fl F Ar flavor | Fl -flavor Ar flavor 68.Op Fl s | Fl S 69.Op Fl v 70.Op Fl z 71.Ar archive 72.Ar 73.Nm 74.Fl r 75.Op Fl T 76.Op Fl a Ar position-after 77.Op Fl b Ar position-before 78.Op Fl c 79.Op Fl D 80.Op Fl f 81.Op Fl F Ar flavor | Fl -flavor Ar flavor 82.Op Fl i Ar position-before 83.Op Fl j 84.Op Fl s | Fl S 85.Op Fl u 86.Op Fl v 87.Op Fl z 88.Ar archive 89.Ar 90.Nm 91.Fl s 92.Op Fl D 93.Op Fl j 94.Op Fl z 95.Ar archive 96.Nm 97.Fl t 98.Op Fl f 99.Op Fl T 100.Op Fl v 101.Ar archive 102.Op Ar 103.Nm 104.Fl x 105.Op Fl C 106.Op Fl T 107.Op Fl f 108.Op Fl o 109.Op Fl u 110.Op Fl v 111.Ar archive 112.Op Ar 113.Nm 114.Fl M 115.Nm 116.Fl V 117.Sh DESCRIPTION 118The 119.Nm 120utility creates and maintains groups of files combined into an 121archive. 122Once an archive has been created, new files can be added to it, and 123existing files can be extracted, deleted or replaced. 124.Pp 125Files are named in the archive by their last file name component, 126so if a file referenced by a path containing a 127.Dq / 128is archived, it will be named by the last component of the path. 129Similarly when matching paths listed on the command line against 130file names stored in the archive, only the last component of the 131path will be compared. 132.Pp 133The normal use of 134.Nm 135is for the creation and maintenance of libraries suitable for use 136with the link editor 137.Xr ld 1 , 138although it is not restricted to this purpose. 139The 140.Nm 141utility can create and manage an archive symbol table (see 142.Xr ar 5 ) 143used to speed up link editing operations. 144If a symbol table is present in an archive, it will be 145kept up-to-date by subsequent operations on the archive. 146.Sh OPTIONS 147The 148.Nm 149utility supports the following options: 150.Bl -tag -width indent 151.It Fl a Ar member-after 152When used with option 153.Fl m 154this option specifies that the archive members specified by 155arguments 156.Ar 157are moved to after the archive member named by argument 158.Ar member-after . 159When used with option 160.Fl r 161this option specifies that the files specified by arguments 162.Ar 163are added after the archive member named by argument 164.Ar member-after . 165.It Fl b Ar member-before 166When used with option 167.Fl m 168this option specifies that the archive members specified by 169arguments 170.Ar 171are moved to before the archive member named by argument 172.Ar member-before . 173When used with option 174.Fl r 175this option specifies that the files specified by arguments 176.Ar 177are added before the archive member named by argument 178.Ar member-before . 179.It Fl c 180Suppress the informational message printed when a new archive is 181created using the 182.Fl r 183and 184.Fl q 185options. 186.It Fl C 187Prevent extracted files from replacing like-named files 188in the file system. 189.It Fl d 190Delete the members named by arguments 191.Ar 192from the archive specified by argument 193.Ar archive . 194The archive's symbol table, if present, is updated to reflect 195the new contents of the archive. 196.It Fl D 197When used in combination with the 198.Fl r 199or 200.Fl q 201option, insert 0's instead of the real mtime, uid and gid values 202and 0644 instead of file mode from the members named by arguments 203.Ar . 204This ensures that checksums on the resulting archives are reproducible 205when member contents are identical. 206.It Fl f 207Synonymous with option 208.Fl T . 209.It Fl F Ar flavor | Fl -flavor Ar flavor 210Create archives with the specified archive format. 211Legal values for argument 212.Ar flavor 213are: 214.Bl -tag -width indent -compact 215.It Ar bsd 216Create BSD format archives. 217.It Ar gnu 218An alias for 219.Ar svr4 . 220.It Ar svr4 221Create SVR4 format archives. 222.El 223If this option is not specified, 224.Nm 225will create archives using the SVR4 format. 226.It Fl i Ar member-before 227Synonymous with option 228.Fl b . 229.It Fl j 230This option is accepted for compatibility with the 231.Tn FreeBSD 232version of the 233.Nm 234utility, but is ignored. 235.It Fl l 236This option is accepted for compatibility with GNU 237.Xr ar 1 , 238but is ignored. 239.It Fl m 240Move archive members specified by arguments 241.Ar 242within the archive. 243If a position has been specified by one of the 244.Fl a , 245.Fl b 246or 247.Fl i 248options, the members are moved to before or after the specified 249position. 250If no position has been specified, the specified members are moved 251to the end of the archive. 252If the archive has a symbol table, it is updated to reflect the 253new contents of the archive. 254.It Fl M 255Read and execute MRI librarian commands from standard input. 256The commands understood by the 257.Nm 258utility are described in the section 259.Sx "MRI Librarian Commands" . 260.It Fl o 261Preserve the original modification times of members when extracting 262them. 263.It Fl p 264Write the contents of the specified archive members named by 265arguments 266.Ar 267to standard output. 268If no members were specified, the contents of all the files in the 269archive are written in the order they appear in the archive. 270.It Fl q 271Append the files specified by arguments 272.Ar 273to the archive specified by argument 274.Ar archive 275without checking if the files already exist in the archive. 276The archive symbol table will be updated as needed. 277If the file specified by the argument 278.Ar archive 279does not already exist, a new archive will be created. 280.It Fl r 281Replace (add) the files specified by arguments 282.Ar 283in the archive specified by argument 284.Ar archive , 285creating the archive if necessary. 286Replacing existing members will not change the order of members within 287the archive. 288If a file named in arguments 289.Ar 290does not exist, existing members in the archive that match that 291name are not changed. 292New files are added to the end of the archive unless one of the 293positioning options 294.Fl a , 295.Fl b 296or 297.Fl i 298is specified. 299The archive symbol table, if it exists, is updated to reflect the 300new state of the archive. 301.It Fl s 302Add an archive symbol table (see 303.Xr ar 5 ) 304to the archive specified by argument 305.Ar archive . 306Invoking 307.Nm 308with the 309.Fl s 310option alone is equivalent to invoking 311.Xr ranlib 1 . 312.It Fl S 313Do not generate an archive symbol table. 314.It Fl t 315For 316.Nm , 317list the files specified by arguments 318.Ar 319in the order in which they appear in the archive, one per line. 320If no files are specified, all files in the archive are listed. 321.It Fl T 322Use only the first fifteen characters of the archive member name or 323command line file name argument when naming archive members. 324.It Fl u 325Conditionally update the archive or extract members. 326When used with the 327.Fl r 328option, files named by arguments 329.Ar 330will be replaced in the archive if they are newer than their 331archived versions. 332When used with the 333.Fl x 334option, the members specified by arguments 335.Ar 336will be extracted only if they are newer than the corresponding 337files in the file system. 338.It Fl v 339Provide verbose output. 340When used with the 341.Fl d , 342.Fl m , 343.Fl q 344or 345.Fl x 346options, 347.Nm 348gives a file-by-file description of the archive modification being 349performed, which consists of three white-space separated fields: 350the option letter, a dash 351.Dq "-" , 352and the file name. 353When used with the 354.Fl r 355option, 356.Nm 357displays the description as above, but the initial letter is an 358.Dq a 359if the file is added to the archive, or an 360.Dq r 361if the file replaces a file already in the archive. 362When used with the 363.Fl p 364option, the name of the file enclosed in 365.Dq < 366and 367.Dq > 368characters is written to standard output preceded by a single newline 369character and followed by two newline characters. 370The contents of the named file follow the file name. 371When used with the 372.Fl t 373option, 374.Nm 375displays eight whitespace separated fields: 376the file permissions as displayed by 377.Xr strmode 3 , 378decimal user and group IDs separated by a slash ( 379.Dq / Ns ) , 380the file size in bytes, the file modification time in 381.Xr strftime 3 382format 383.Dq "%b %e %H:%M %Y" , 384and the name of the file. 385.It Fl V 386Print a version identifier and exit. 387.It Fl x 388Extract archive members specified by arguments 389.Ar 390into the current directory. 391If no members have been specified, extract all members of the archive. 392If the file corresponding to an extracted member does not exist it 393will be created. 394If the file corresponding to an extracted member does exist, its owner 395and group will not be changed while its contents will be overwritten 396and its permissions will set to that entered in the archive. 397The file's access and modification time would be that of the time 398of extraction unless the 399.Fl o 400option was specified. 401.It Fl z 402This option is accepted for compatibility with the 403.Tn FreeBSD 404version of the 405.Nm 406utility, but is ignored. 407.El 408.Ss "MRI Librarian Commands" 409If the 410.Fl M 411option is specified, the 412.Nm 413utility will read and execute commands from its standard input. 414If standard input is a terminal, the 415.Nm 416utility will display the prompt 417.Dq Li "AR >" 418before reading a line, and will continue operation even if errors are 419encountered. 420If standard input is not a terminal, the 421.Nm 422utility will not display a prompt and will terminate execution on 423encountering an error. 424.Pp 425Each input line contains a single command. 426Words in an input line are separated by whitespace characters. 427The first word of the line is the command, the remaining words are 428the arguments to the command. 429The command word may be specified in either case. 430Arguments may be separated by commas or blanks. 431.Pp 432Empty lines are allowed and are ignored. 433Long lines are continued by ending them with the 434.Dq Li + 435character. 436.Pp 437The 438.Dq Li * 439and 440.Dq Li "\;" 441characters start a comment. 442Comments extend till the end of the line. 443.Pp 444When executing an MRI librarian script the 445.Nm 446utility works on a temporary copy of an archive. 447Changes to the copy are made permanent using the 448.Ic save 449command. 450.Pp 451Commands understood by the 452.Nm 453utility are: 454.Bl -tag -width indent 455.It Ic addlib Ar archive | Ic addlib Ar archive Pq Ar member Oo Li , Ar member Oc Ns ... 456Add the contents of the archive named by argument 457.Ar archive 458to the current archive. 459If specific members are named using the arguments 460.Ar member , 461then those members are added to the current archive. 462If no members are specified, the entire contents of the archive 463are added to the current archive. 464.It Ic addmod Ar member Oo Li , Ar member Oc Ns ... 465Add the files named by arguments 466.Ar member 467to the current archive. 468.It Ic clear 469Discard all the contents of the current archive. 470.It Ic create Ar archive 471Create a new archive named by the argument 472.Ar archive , 473and makes it the current archive. 474If the named archive already exists, it will be overwritten 475when the 476.Ic save 477command is issued. 478.It Ic delete Ar module Oo Li , Ar member Oc Ns ... 479Delete the modules named by the arguments 480.Ar member 481from the current archive. 482.It Ic directory Ar archive Po Ar member Oo Li , Ar member Oc Ns ... Pc Op Ar outputfile 483List each named module in the archive. 484The format of the output depends on the verbosity setting set using 485the 486.Ic verbose 487command. 488Output is sent to standard output, or to the file specified by 489argument 490.Ar outputfile . 491.It Ic end 492Exit successfully from the 493.Nm 494utility. 495Any unsaved changes to the current archive will be discarded. 496.It Ic extract Ar member Oo Li , Ar member Oc Ns ... 497Extract the members named by the arguments 498.Ar member 499from the current archive. 500.It Ic list 501Display the contents of the current archive in verbose style. 502.It Ic open Ar archive 503Open the archive named by argument 504.Ar archive 505and make it the current archive. 506.It Ic replace Ar member Oo Li , Ar member Oc Ns ... 507Replace named members in the current archive with the files specified 508by arguments 509.Ar member . 510The files must be present in the current directory and the named 511modules must already exist in the current archive. 512.It Ic save 513Commit all changes to the current archive. 514.It Ic verbose 515Toggle the verbosity of the 516.Ic directory 517command. 518.El 519.Sh EXAMPLES 520To create a new archive 521.Pa ex.a 522containing three files 523.Pa ex1.o , 524.Pa ex2.o 525and 526.Pa ex3.o , 527use: 528.Dl "ar -rc ex.a ex1.o ex2.o ex3.o" 529.Pp 530To add an archive symbol table to an existing archive 531.Pa ex.a , 532use: 533.Dl "ar -s ex.a" 534.Pp 535To delete file 536.Pa ex1.o 537from archive 538.Pa ex.a , 539use: 540.D1 "ar -d ex.a ex1.o" 541.Pp 542To verbosely list the contents of archive 543.Pa ex.a , 544use: 545.D1 "ar -tv ex.a" 546.Pp 547To create a new archive 548.Pa ex.a 549containing the files 550.Pa ex1.o , 551and 552.Pa ex2.o , 553using MRI librarian commands, use the following script: 554.Bd -literal -offset indent 555create ex.a * specify the output archive 556addmod ex1.o ex2.o * add modules 557save * save pending changes 558end * exit the utility 559.Ed 560.Sh DIAGNOSTICS 561.Ex -std 562.Sh SEE ALSO 563.Xr ld 1 , 564.Xr ranlib 1 , 565.Xr archive 3 , 566.Xr elf 3 , 567.Xr strftime 3 , 568.Xr strmode 3 , 569.Xr ar 5 570.Sh STANDARDS COMPLIANCE 571The 572.Nm 573utility's support for the 574.Fl a , 575.Fl b , 576.Fl c , 577.Fl i , 578.Fl m , 579.Fl p , 580.Fl q , 581.Fl r , 582.Fl s , 583.Fl t , 584.Fl u , 585.Fl v , 586.Fl C 587and 588.Fl T 589options is believed to be compliant with 590.St -p1003.2 . 591.Sh HISTORY 592An 593.Nm 594command first appeared in AT&T UNIX Version 1. 595In 596.Fx 8.0 , 597.An Kai Wang Aq Mt kaiw@FreeBSD.org 598reimplemented 599.Nm 600using the 601.Lb libarchive 602and the 603.Lb libelf . 604