1.\" Copyright (c) 2003-2007 Tim Kientzle 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.\" $FreeBSD$ 26.\" 27.Dd September 16, 2014 28.Dt CPIO 1 29.Os 30.Sh NAME 31.Nm cpio 32.Nd copy files to and from archives 33.Sh SYNOPSIS 34.Nm 35.Fl i 36.Op Ar options 37.Op Ar pattern ... 38.Op Ar < archive 39.Nm 40.Fl o 41.Op Ar options 42.Ar < name-list 43.Op Ar > archive 44.Nm 45.Fl p 46.Op Ar options 47.Ar dest-dir 48.Ar < name-list 49.Sh DESCRIPTION 50.Nm 51copies files between archives and directories. 52This implementation can extract from tar, pax, cpio, zip, jar, ar, 53and ISO 9660 cdrom images and can create tar, pax, cpio, ar, 54and shar archives. 55.Pp 56The first option to 57.Nm 58is a mode indicator from the following list: 59.Bl -tag -compact -width indent 60.It Fl i 61Input. 62Read an archive from standard input (unless overridden) and extract the 63contents to disk or (if the 64.Fl t 65option is specified) 66list the contents to standard output. 67If one or more file patterns are specified, only files matching 68one of the patterns will be extracted. 69.It Fl o 70Output. 71Read a list of filenames from standard input and produce a new archive 72on standard output (unless overridden) containing the specified items. 73.It Fl p 74Pass-through. 75Read a list of filenames from standard input and copy the files to the 76specified directory. 77.El 78.Pp 79.Sh OPTIONS 80Unless specifically stated otherwise, options are applicable in 81all operating modes. 82.Bl -tag -width indent 83.It Fl 0 , Fl Fl null 84Read filenames separated by NUL characters instead of newlines. 85This is necessary if any of the filenames being read might contain newlines. 86.It Fl A 87(o mode only) 88Append to the specified archive. 89(Not yet implemented.) 90.It Fl a 91(o and p modes) 92Reset access times on files after they are read. 93.It Fl B 94(o mode only) 95Block output to records of 5120 bytes. 96.It Fl C Ar size 97(o mode only) 98Block output to records of 99.Ar size 100bytes. 101.It Fl c 102(o mode only) 103Use the old POSIX portable character format. 104Equivalent to 105.Fl Fl format Ar odc . 106.It Fl d , Fl Fl make-directories 107(i and p modes) 108Create directories as necessary. 109.It Fl E Ar file 110(i mode only) 111Read list of file name patterns from 112.Ar file 113to list and extract. 114.It Fl F Ar file , Fl Fl file Ar file 115Read archive from or write archive to 116.Ar file . 117.It Fl f Ar pattern 118(i mode only) 119Ignore files that match 120.Ar pattern . 121.It Fl H Ar format , Fl Fl format Ar format 122(o mode only) 123Produce the output archive in the specified format. 124Supported formats include: 125.Pp 126.Bl -tag -width "iso9660" -compact 127.It Ar cpio 128Synonym for 129.Ar odc . 130.It Ar newc 131The SVR4 portable cpio format. 132.It Ar odc 133The old POSIX.1 portable octet-oriented cpio format. 134.It Ar pax 135The POSIX.1 pax format, an extension of the ustar format. 136.It Ar ustar 137The POSIX.1 tar format. 138.El 139.Pp 140The default format is 141.Ar odc . 142See 143.Xr libarchive-formats 5 144for more complete information about the 145formats currently supported by the underlying 146.Xr libarchive 3 147library. 148.It Fl h , Fl Fl help 149Print usage information. 150.It Fl I Ar file 151Read archive from 152.Ar file . 153.It Fl i , Fl Fl extract 154Input mode. 155See above for description. 156.It Fl Fl insecure 157(i and p mode only) 158Disable security checks during extraction or copying. 159This allows extraction via symbolic links, absolute paths, 160and path names containing 161.Sq .. 162in the name. 163.It Fl J , Fl Fl xz 164(o mode only) 165Compress the file with xz-compatible compression before writing it. 166In input mode, this option is ignored; xz compression is recognized 167automatically on input. 168.It Fl j 169Synonym for 170.Fl y . 171.It Fl L 172(o and p modes) 173All symbolic links will be followed. 174Normally, symbolic links are archived and copied as symbolic links. 175With this option, the target of the link will be archived or copied instead. 176.It Fl l , Fl Fl link 177(p mode only) 178Create links from the target directory to the original files, 179instead of copying. 180.It Fl Fl lrzip 181(o mode only) 182Compress the resulting archive with 183.Xr lrzip 1 . 184In input mode, this option is ignored. 185.It Fl Fl lz4 186(o mode only) 187Compress the archive with lz4-compatible compression before writing it. 188In input mode, this option is ignored; lz4 compression is recognized 189automatically on input. 190.It Fl Fl zstd 191(o mode only) 192Compress the archive with zstd-compatible compression before writing it. 193In input mode, this option is ignored; zstd compression is recognized 194automatically on input. 195.It Fl Fl lzma 196(o mode only) 197Compress the file with lzma-compatible compression before writing it. 198In input mode, this option is ignored; lzma compression is recognized 199automatically on input. 200.It Fl Fl lzop 201(o mode only) 202Compress the resulting archive with 203.Xr lzop 1 . 204In input mode, this option is ignored. 205.It Fl Fl passphrase Ar passphrase 206The 207.Pa passphrase 208is used to extract or create an encrypted archive. 209Currently, zip is only a format that 210.Nm 211can handle encrypted archives. 212You shouldn't use this option unless you realize how insecure 213use of this option is. 214.It Fl m , Fl Fl preserve-modification-time 215(i and p modes) 216Set file modification time on created files to match 217those in the source. 218.It Fl n , Fl Fl numeric-uid-gid 219(i mode, only with 220.Fl t ) 221Display numeric uid and gid. 222By default, 223.Nm 224displays the user and group names when they are provided in the 225archive, or looks up the user and group names in the system 226password database. 227.It Fl Fl no-preserve-owner 228(i mode only) 229Do not attempt to restore file ownership. 230This is the default when run by non-root users. 231.It Fl O Ar file 232Write archive to 233.Ar file . 234.It Fl o , Fl Fl create 235Output mode. 236See above for description. 237.It Fl p , Fl Fl pass-through 238Pass-through mode. 239See above for description. 240.It Fl Fl preserve-owner 241(i mode only) 242Restore file ownership. 243This is the default when run by the root user. 244.It Fl Fl quiet 245Suppress unnecessary messages. 246.It Fl R Oo user Oc Ns Oo : Oc Ns Oo group Oc , Fl Fl owner Oo user Oc Ns Oo : Oc Ns Oo group Oc 247Set the owner and/or group on files in the output. 248If group is specified with no user 249(for example, 250.Fl R Ar :wheel ) 251then the group will be set but not the user. 252If the user is specified with a trailing colon and no group 253(for example, 254.Fl R Ar root: ) 255then the group will be set to the user's default group. 256If the user is specified with no trailing colon, then 257the user will be set but not the group. 258In 259.Fl i 260and 261.Fl p 262modes, this option can only be used by the super-user. 263(For compatibility, a period can be used in place of the colon.) 264.It Fl r 265(All modes.) 266Rename files interactively. 267For each file, a prompt is written to 268.Pa /dev/tty 269containing the name of the file and a line is read from 270.Pa /dev/tty . 271If the line read is blank, the file is skipped. 272If the line contains a single period, the file is processed normally. 273Otherwise, the line is taken to be the new name of the file. 274.It Fl t , Fl Fl list 275(i mode only) 276List the contents of the archive to stdout; 277do not restore the contents to disk. 278.It Fl u , Fl Fl unconditional 279(i and p modes) 280Unconditionally overwrite existing files. 281Ordinarily, an older file will not overwrite a newer file on disk. 282.It Fl V , Fl Fl dot 283Print a dot to stderr for each file as it is processed. 284Superseded by 285.Fl v . 286.It Fl v , Fl Fl verbose 287Print the name of each file to stderr as it is processed. 288With 289.Fl t , 290provide a detailed listing of each file. 291.It Fl Fl version 292Print the program version information and exit. 293.It Fl y 294(o mode only) 295Compress the archive with bzip2-compatible compression before writing it. 296In input mode, this option is ignored; 297bzip2 compression is recognized automatically on input. 298.It Fl Z 299(o mode only) 300Compress the archive with compress-compatible compression before writing it. 301In input mode, this option is ignored; 302compression is recognized automatically on input. 303.It Fl z 304(o mode only) 305Compress the archive with gzip-compatible compression before writing it. 306In input mode, this option is ignored; 307gzip compression is recognized automatically on input. 308.El 309.Sh EXIT STATUS 310.Ex -std 311.Sh ENVIRONMENT 312The following environment variables affect the execution of 313.Nm : 314.Bl -tag -width ".Ev BLOCKSIZE" 315.It Ev LANG 316The locale to use. 317See 318.Xr environ 7 319for more information. 320.It Ev TZ 321The timezone to use when displaying dates. 322See 323.Xr environ 7 324for more information. 325.El 326.Sh EXAMPLES 327The 328.Nm 329command is traditionally used to copy file hierarchies in conjunction 330with the 331.Xr find 1 332command. 333The first example here simply copies all files from 334.Pa src 335to 336.Pa dest : 337.Dl Nm find Pa src | Nm Fl pmud Pa dest 338.Pp 339By carefully selecting options to the 340.Xr find 1 341command and combining it with other standard utilities, 342it is possible to exercise very fine control over which files are copied. 343This next example copies files from 344.Pa src 345to 346.Pa dest 347that are more than 2 days old and whose names match a particular pattern: 348.Dl Nm find Pa src Fl mtime Ar +2 | Nm grep foo[bar] | Nm Fl pdmu Pa dest 349.Pp 350This example copies files from 351.Pa src 352to 353.Pa dest 354that are more than 2 days old and which contain the word 355.Do foobar Dc : 356.Dl Nm find Pa src Fl mtime Ar +2 | Nm xargs Nm grep -l foobar | Nm Fl pdmu Pa dest 357.Sh COMPATIBILITY 358The mode options i, o, and p and the options 359a, B, c, d, f, l, m, r, t, u, and v comply with SUSv2. 360.Pp 361The old POSIX.1 standard specified that only 362.Fl i , 363.Fl o , 364and 365.Fl p 366were interpreted as command-line options. 367Each took a single argument of a list of modifier 368characters. 369For example, the standard syntax allows 370.Fl imu 371but does not support 372.Fl miu 373or 374.Fl i Fl m Fl u , 375since 376.Ar m 377and 378.Ar u 379are only modifiers to 380.Fl i , 381they are not command-line options in their own right. 382The syntax supported by this implementation is backwards-compatible 383with the standard. 384For best compatibility, scripts should limit themselves to the 385standard syntax. 386.Sh SEE ALSO 387.Xr bzip2 1 , 388.Xr tar 1 , 389.Xr gzip 1 , 390.Xr mt 1 , 391.Xr pax 1 , 392.Xr libarchive 3 , 393.Xr cpio 5 , 394.Xr libarchive-formats 5 , 395.Xr tar 5 396.Sh STANDARDS 397There is no current POSIX standard for the cpio command; it appeared 398in 399.St -p1003.1-96 400but was dropped from 401.St -p1003.1-2001 . 402.Pp 403The cpio, ustar, and pax interchange file formats are defined by 404.St -p1003.1-2001 405for the pax command. 406.Sh HISTORY 407The original 408.Nm cpio 409and 410.Nm find 411utilities were written by Dick Haight 412while working in AT&T's Unix Support Group. 413They first appeared in 1977 in PWB/UNIX 1.0, the 414.Dq Programmer's Work Bench 415system developed for use within AT&T. 416They were first released outside of AT&T as part of System III Unix in 1981. 417As a result, 418.Nm cpio 419actually predates 420.Nm tar , 421even though it was not well-known outside of AT&T until some time later. 422.Pp 423This is a complete re-implementation based on the 424.Xr libarchive 3 425library. 426.Sh BUGS 427The cpio archive format has several basic limitations: 428It does not store user and group names, only numbers. 429As a result, it cannot be reliably used to transfer 430files between systems with dissimilar user and group numbering. 431Older cpio formats limit the user and group numbers to 43216 or 18 bits, which is insufficient for modern systems. 433The cpio archive formats cannot support files over 4 gigabytes, 434except for the 435.Dq odc 436variant, which can support files up to 8 gigabytes. 437