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