2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
43 .\" Copyright 1989 AT&T
44 .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
45 .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved
46 .\" Copyright (c) 2012 Gary Mills
48 .TH CPIO 1 "Aug 3, 2009"
50 cpio \- copy file archives in and out
54 \fBcpio\fR \fB-i\fR [\fB-bBcdfkmPqrsStuvV6@/\fR] [\fB-C\fR \fIbufsize\fR] [\fB-E\fR \fIfile\fR]
55 [\fB-H\fR \fIheader\fR] [\fB-I\fR \fI\fR [\fB-M\fR \fImessage\fR]] [\fB-R\fR \fIid\fR] [\fIpattern\fR]...
60 \fBcpio\fR \fB-o\fR [\fB-aABcLPqvV@/\fR] [\fB-C\fR \fIbufsize\fR] [\fB-H\fR \fIheader\fR]
61 [\fB-O\fR \fIfile\fR [\fB-M\fR \fImessage\fR]]
66 \fBcpio\fR \fB-p\fR [\fB-adlLmPquvV@/\fR] [\fB-R\fR \fIid\fR] \fIdirectory\fR
72 The \fBcpio\fR command copies files into and out of a \fBcpio\fR archive. The
73 \fBcpio\fR archive can span multiple volumes. The \fB-i\fR, \fB-o\fR, and
74 \fB-p\fR options select the action to be performed. The following list
75 describes each of the actions. These actions are mutually exclusive.
79 \fBcpio\fR \fB-i\fR (copy in) extracts files from the standard input, which is
80 assumed to be the product of a previous \fBcpio\fR \fB-o\fR command. Only files
81 with names that match one of the \fIpattern\fRs are selected. See \fBsh\fR(1)
82 and OPERANDS for more information about \fIpattern\fR. Extracted files are
83 conditionally copied into the current directory tree, based on the options
84 described below. The permissions of the files are those of the previous \fBcpio
85 -o\fR command. The owner and group are the same as the current user, unless the
86 current user has the \fB{PRIV_FILE_CHOWN_SELF}\fR privilege. See
87 \fBchown\fR(2). If this is the case, owner and group are the same as those
88 resulting from the previous \fBcpio -o\fR command. Notice that if \fBcpio\fR
89 \fB-i\fR tries to create a file that already exists and the existing file is
90 the same age or younger (\fBnewer\fR), \fBcpio\fR outputs a warning message and
91 not replace the file. The \fB-u\fR option can be used to unconditionally
92 overwrite the existing file.
96 \fBcpio\fR \fB-o\fR (copy out) reads a list of file path names from the
97 standard input and copies those files to the standard output, together with
98 path name and status information in the form of a \fBcpio\fR archive. Output is
99 padded to an 8192-byte boundary by default or to the user-specified block size
100 (with the \fB-B\fR or \fB-C\fR options) or to some device-dependent block size
101 where necessary (as with the CTC tape).
105 \fBcpio\fR \fB-p\fR (pass) reads a list of file path names from the standard
106 input and conditionally copies those files into the destination directory tree,
107 based on the options described below.
110 If the underlying file system of the source file supports detection of holes as
111 reported by \fBpathconf\fR(2), the file is a sparse file, and the destination
112 file is seekable, then holes in sparse files are preserved in pass mode,
113 otherwise holes are filled with zeros.
116 \fBcpio\fR assumes four-byte words.
119 If, when writing to a character device (\fB-o\fR) or reading from a character
120 device (\fB-i\fR), \fBcpio\fR reaches the end of a medium (such as the end of a
121 diskette), and the \fB-O\fR and \fB-I\fR options are not used, \fBcpio\fR
122 prints the following message:
126 To continue, type device/file name when ready.
133 To continue, you must replace the medium and type the character special device
134 name (\fB/dev/rdiskette\fR for example) and press RETURN. You might want to
135 continue by directing \fBcpio\fR to use a different device. For example, if you
136 have two floppy drives you might want to switch between them so \fBcpio\fR can
137 proceed while you are changing the floppies. Press RETURN to cause the
138 \fBcpio\fR process to exit.
142 The following options are supported:
149 (copy in) Reads an archive from the standard input and conditionally extracts
150 the files contained in it and places them into the current directory tree.
159 (copy out) Reads a list of file path names from the standard input and copies
160 those files to the standard output in the form of a \fBcpio\fR archive.
169 (pass) Reads a list of file path names from the standard input and
170 conditionally copies those files into the destination directory tree.
175 The following options can be appended in any sequence to the \fB-i\fR,
176 \fB-o\fR, or \fB-p\fR options:
183 Resets access times of input files after they have been copied, making
184 \fBcpio\fR's access invisible. Access times are not reset for linked files when
185 \fBcpio\fR \fB-pla\fR is specified.
194 Appends files to an archive. The \fB-A\fR option requires the \fB-O\fR option.
195 Valid only with archives that are files, or that are on floppy diskettes or
196 hard disk partitions. The effect on files that are linked in the existing
197 portion of the archive is unpredictable.
206 Reverses the order of the bytes within each word. Use only with the \fB-i\fR
216 Blocks input/output 5120 bytes to the record. The default buffer size is 8192
217 bytes when this and the \fB-C\fR options are not used. \fB-B\fR does not apply
218 to the \fB-p\fR (pass) option.
227 Reads or writes header information in \fBASCII\fR character form for
228 portability. There are no \fBUID\fR or \fBGID\fR restrictions associated with
229 this header format. Use this option between SVR4-based machines, or the
230 \fB-H\fR \fBodc\fR option between unknown machines. The \fB-c\fR option implies
231 the use of expanded device numbers, which are only supported on SVR4-based
232 systems. When transferring files between SunOS 4 or Interactive UNIX and the
233 Solaris 2.6 Operating environment or compatible versions, use \fB-H\fR
240 \fB\fB-C\fR \fIbufsize\fR\fR
243 Blocks input/output \fIbufsize\fR bytes to the record, where \fIbufsize\fR is
244 replaced by a positive integer. The default buffer size is 8192 bytes when this
245 and \fB-B\fR options are not used. \fB-C\fR does not apply to the \fB-p\fR
255 Creates directories as needed.
261 \fB\fB-E\fR \fIfile\fR\fR
264 Specifies an input file (\fIfile\fR) that contains a list of filenames to be
265 extracted from the archive (one filename per line).
274 Copies in all files except those in \fIpattern\fRs. See OPERANDS for a
275 description of \fIpattern\fR.
281 \fB\fB-H\fR \fIheader\fR\fR
284 Reads or writes header information in \fIheader\fR format. Always use this
285 option or the \fB-c\fR option when the origin and the destination machines are
286 different types. This option is mutually exclusive with options \fB-c\fR and
289 Valid values for \fIheader\fR are:
296 \fBbar\fR head and format. Used only with the \fB-i\fR option ( read only).
302 \fB\fBcrc\fR | \fBCRC\fR\fR
305 \fBASCII\fR header with expanded device numbers and an additional per-file
306 checksum. There are no \fBUID\fR or \fBGID\fR restrictions associated with this
316 \fBASCII\fR header with small device numbers. This is the IEEE/P1003 Data
317 Interchange Standard cpio header and format. It has the widest range of
318 portability of any of the header formats. It is the official format for
319 transferring files between POSIX-conforming systems (see \fBstandards\fR(5)).
320 Use this format to communicate with SunOS 4 and Interactive UNIX. This header
321 format allows \fBUID\fRs and \fBGID\fRs up to 262143 to be stored in the
328 \fB\fBtar\fR | \fBTAR\fR\fR
331 \fBtar\fR header and format. This is an older \fBtar\fR header format that
332 allows \fBUID\fRs and \fBGID\fRs up to 2097151 to be stored in the header. It
333 is provided for the reading of legacy archives only, that is, in conjunction
334 with option \fB-i\fR.
336 Specifying this archive format with option \fB-o\fR has the same effect as
337 specifying the "ustar" format: the output archive is in \fBustar\fR format, and
338 must be read using \fB-H\fR \fBustar\fR.
344 \fB\fBustar\fR | \fBUSTAR\fR\fR
347 IEEE/P1003 Data Interchange Standard tar header and format. This header format
348 allows \fBUID\fRs and \fBGID\fRs up to 2097151 to be stored in the header.
351 Files with \fBUID\fRs and \fBGID\fRs greater than the limit stated above are
352 archived with the \fBUID\fR and \fBGID\fR of \fB60001\fR. To transfer a large
353 file (8 Gb \(em 1 byte), the header format can be \fBtar|TAR\fR,
354 \fBustar|USTAR\fR, or \fBodc\fR only.
360 \fB\fB-I\fR \fIfile\fR\fR
363 Reads the contents of \fIfile\fR as an input archive, instead of the standard
364 input. If \fIfile\fR is a character special device, and the current medium has
365 been completely read, replace the medium and press RETURN to continue to the
366 next medium. This option is used only with the \fB-i\fR option.
375 Attempts to skip corrupted file headers and I/O errors that might be
376 encountered. If you want to copy files from a medium that is corrupted or out
377 of sequence, this option lets you read only those files with good headers. For
378 \fBcpio\fR archives that contain other \fBcpio\fR archives, if an error is
379 encountered, \fBcpio\fR can terminate prematurely. \fBcpio\fR finds the next
380 good header, which can be one for a smaller archive, and terminate when the
381 smaller archive's trailer is encountered. Use only with the \fB-i\fR option.
390 In pass mode, makes hard links between the source and destination whenever
391 possible. If the \fB-L\fR option is also specified, the hard link is to the
392 file referred to by the symbolic link. Otherwise, the hard link is to the
393 symbolic link itself. Use only with the \fB-p\fR option.
402 Follows symbolic links. If a symbolic link to a directory is encountered,
403 archives the directory referred to by the link, using the name of the link.
404 Otherwise, archives the file referred to by the link, using the name of the
414 Retains previous file modification time. This option is ineffective on
415 directories that are being copied.
421 \fB\fB-M\fR \fImessage\fR\fR
424 Defines a \fImessage\fR to use when switching media. When you use the \fB-O\fR
425 or \fB-I\fR options and specify a character special device, you can use this
426 option to define the message that is printed when you reach the end of the
427 medium. One \fB%d\fR can be placed in \fImessage\fR to print the sequence
428 number of the next medium needed to continue.
434 \fB\fB-O\fR \fIfile\fR\fR
437 Directs the output of \fBcpio\fR to \fIfile\fR, instead of the standard output.
438 If \fIfile\fR is a character special device and the current medium is full,
439 replace the medium and type a carriage return to continue to the next medium.
440 Use only with the \fB-o\fR option.
449 Preserves \fBACL\fRs. If the option is used for output, existing \fBACL\fRs are
450 written along with other attributes, except for extended attributes, to the
451 standard output. \fBACL\fRs are created as special files with a special file
452 type. If the option is used for input, existing \fBACL\fRs are extracted along
453 with other attributes from standard input. The option recognizes the special
454 file type. Notice that errors occurs if a \fBcpio\fR archive with \fBACL\fRs is
455 extracted by previous versions of \fBcpio\fR. This option should not be used
456 with the \fB-c\fR option, as \fBACL\fR support might not be present on all
457 systems, and hence is not portable. Use \fBASCII\fR headers for portability.
466 Quiet. Suppresses the number of blocks message that normally is printed
467 after the copy is completed.
476 Interactively renames files. If the user types a carriage return alone, the
477 file is skipped. If the user types a ``.'', the original pathname is retained.
478 Not available with \fBcpio\fR \fB-p\fR.
484 \fB\fB-R\fR \fIid\fR\fR
487 Reassigns ownership and group information for each file to user ID. (ID must be
488 a valid login ID from the \fBpasswd\fR database.) This option is valid only
489 when id is the invoking user or the super-user. See \fBNOTES\fR.
498 Swaps bytes within each half word.
507 Swaps halfwords within each word.
516 Prints a table of contents of the input. If any file in the table of contents
517 has extended attributes, these are also listed. No files are created. \fB-t\fR
518 and \fB-V\fR are mutually exclusive.
527 Copies unconditionally. Normally, an older file is not replaced a newer file
528 with the same name, although an older directory updates a newer directory.
537 Verbose. Prints a list of file and extended attribute names. When used with the
538 \fB-t\fR option, the table of contents looks like the output of an \fBls\fR
539 \fB-l\fR command (see \fBls\fR(1)).
548 Special verbose. Prints a dot for each file read or written. Useful to assure
549 the user that \fBcpio\fR is working without printing out all file names.
558 Processes a UNIX System Sixth Edition archive format file. Use only with the
559 \fB-i\fR option. This option is mutually exclusive with \fB-c\fR and \fB-H\fR.
568 Includes extended attributes in archive. By default, \fBcpio\fR does not place
569 extended attributes in the archive. With this flag, \fBcpio\fR looks for
570 extended attributes on the files to be placed in the archive and add them, as
571 regular files, to the archive. The extended attribute files go in the archive
572 as special files with special file types. When the \fB-@\fR flag is used with
573 \fB-i\fR or \fB-p\fR, it instructs \fBcpio\fR to restore extended attribute
574 data along with the normal file data. Extended attribute files can only be
575 extracted from an archive as part of a normal file extract. Attempts to
576 explicitly extract attribute records are ignored.
585 Includes extended system attributes in archive. By default, \fBcpio\fR does not
586 place extended system attributes in the archive. With this flag, \fBcpio\fR
587 looks for extended system attributes on the files to be placed in the archive
588 and add them, as regular files, to the archive. The extended attribute files go
589 in the archive as special files with special file types. When the \fB-/\fR flag
590 is used with \fB-i\fR or \fB-p\fR, it instructs \fBcpio\fR to restore extended
591 system attribute data along with the normal file data. Extended system
592 attribute files can only be extracted from an archive as part of a normal file
593 extract. Attempts to explicitly extract attribute records are ignored.
599 The following operands are supported:
603 \fB\fIdirectory\fR\fR
606 A path name of an existing directory to be used as the target of \fBcpio\fR
616 Expressions making use of a pattern-matching notation similar to that used by
617 the shell (see \fBsh\fR(1)) for filename pattern matching, and similar to
618 regular expressions. The following metacharacters are defined:
625 Matches any string, including the empty string.
634 Matches any single character.
643 Matches any one of the enclosed characters. A pair of characters separated by
644 `\(mi' matches any symbol between the pair (inclusive), as defined by the
645 system default collating sequence. If the first character following the opening
646 \fB`['\fR is a \fB`!'\fR, the results are unspecified.
655 The ! (exclamation point) means \fInot\fR. For example, the \fB!abc*\fR pattern
656 would exclude all files that begin with \fBabc\fR.
659 In \fIpattern\fR, metacharacters \fB?\fR, \fB*\fR, and \fB[\fR\|.\|.\|.\fB]\fR
660 match the slash (\fB/\fR) character, and backslash (\fB\e\fR) is an escape
661 character. Multiple cases of \fIpattern\fR can be specified and if no
662 \fIpattern\fR is specified, the default for \fIpattern\fR is \fB*\fR (that is,
665 Each pattern must be enclosed in double quotes. Otherwise, the name of a file
666 in the current directory might be used.
672 See \fBlargefile\fR(5) for the description of the behavior of \fBcpio\fR when
673 encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
677 The following examples show three uses of \fBcpio\fR.
679 \fBExample 1 \fRUsing standard input
683 example% \fBls | cpio -oc > ../newfile\fR
690 When standard input is directed through a pipe to \fBcpio\fR \fB-o\fR, as in
691 the example above, it groups the files so they can be directed (>) to a single
692 file (\fB\&../newfile\fR). The \fB-c\fR option insures that the file is
693 portable to other machines (as would the \fB-H\fR option). Instead of
694 \fBls\fR(1), you could use \fBfind\fR(1), \fBecho\fR(1), \fBcat\fR(1), and so
695 on, to pipe a list of names to \fBcpio\fR. You could direct the output to a
696 device instead of a file.
699 \fBExample 2 \fRExtracting files into directories
703 example% \fBcat newfile | cpio -icd "memo/a1" "memo/b*"\fR
710 In this example, \fBcpio\fR \fB-i\fR uses the output file of \fBcpio\fR
711 \fB-o\fR (directed through a pipe with \fBcat\fR), extracts those files that
712 match the patterns (\fBmemo/a1\fR, \fBmemo/b*\fR), creates directories below
713 the current directory as needed (\fB-d\fR option), and places the files in the
714 appropriate directories. The \fB-c\fR option is used if the input file was
715 created with a portable header. If no patterns were given, all files from
716 \fBnewfile\fR would be placed in the directory.
719 \fBExample 3 \fRCopying or linking files to another directory
723 example% \fBfind . -depth -print | cpio -pdlmv newdir\fR
730 In this example, \fBcpio\fR \fB-p\fR takes the file names piped to it and
731 copies or links (\fB-l\fR option) those files to another directory,
732 \fBnewdir\fR. The \fB-d\fR option says to create directories as needed. The
733 \fB-m\fR option says to retain the modification time. (It is important to use
734 the \fB-depth\fR option of \fBfind\fR(1) to generate path names for \fBcpio\fR.
735 This eliminates problems that \fBcpio\fR could have trying to create files
736 under read-only directories.) The destination directory, \fBnewdir\fR, must
741 Notice that when you use \fBcpio\fR in conjunction with \fBfind\fR, if you use
742 the \fB-L\fR option with \fBcpio\fR, you must use the \fB-follow\fR option with
743 \fBfind\fR and vice versa. Otherwise, there are undesirable results.
746 For multi-reel archives, dismount the old volume, mount the new one, and
747 continue to the next tape by typing the name of the next device (probably the
748 same as the first reel). To stop, type a RETURN and \fBcpio\fR ends.
749 .SH ENVIRONMENT VARIABLES
752 See \fBenviron\fR(5) for descriptions of the following environment variables
753 that affect the execution of \fBcpio\fR: \fBLC_COLLATE\fR, \fBLC_CTYPE\fR,
754 \fBLC_MESSAGES\fR, \fBLC_TIME\fR, \fBTZ\fR, and \fBNLSPATH\fR.
761 \fBcpio\fR creates its temporary file in \fB/var/tmp\fR by default. Otherwise,
762 it uses the directory specified by \fBTMPDIR\fR.
768 The following exit values are returned:
775 Successful completion.
790 See \fBattributes\fR(5) for descriptions of the following attributes:
798 ATTRIBUTE TYPE ATTRIBUTE VALUE
802 Interface Stability Committed
808 \fBar\fR(1), \fBcat\fR(1), \fBecho\fR(1), \fBfind\fR(1), \fBls\fR(1),
809 \fBpax\fR(1), \fBsetfacl\fR(1), \fBsh\fR(1), \fBtar\fR(1), \fBchown\fR(2),
810 \fBarchives.h\fR(3HEAD), \fBattributes\fR(5), \fBenviron\fR(5),
811 \fBfsattr\fR(5), \fBlargefile\fR(5), \fBstandards\fR(5)
815 The maximum path name length allowed in a \fBcpio\fR archive is determined by
816 the header type involved. The following table shows the proper value for each
817 supported archive header type.
824 Header type Command line options Maximum path name length
825 BINARY "\fB-o\fR" 256
826 POSIX "\fB-oH\fR odc" 256
827 ASCII "\fB-oc\fR" 1023
828 CRC "\fB-oH\fR crc" 1023
829 USTAR "\fB-oH\fR ustar" 255
834 When the command line options "\fB-o\fR \fB-H\fR \fBtar\fR" are specified, the
835 archive created is of type \fBUSTAR\fR. This means that it is an error to read
836 this same archive using the command line options "\fB-i\fR \fB-H\fR \fBtar\fR".
837 The archive should be read using the command line options "\fB-i\fR \fB-H\fR
838 \fBustar\fR". The options "\fB-i\fR \fB-H\fR \fBtar\fR" refer to an older tar
842 An error message is output for files whose \fBUID\fR or \fBGID\fR are too large
843 to fit in the selected header format. Use \fB-H\fR \fBcrc\fR or \fB-c\fR to
844 create archives that allow all \fBUID\fR or \fBGID\fR values.
847 Only the super-user can copy special files.
850 Blocks are reported in 512-byte quantities.
853 If a file has \fB000\fR permissions, contains more than 0 characters of data,
854 and the user is not root, the file is not saved or restored.
857 When cpio is invoked in \fBCopy In\fR or \fBPass Mode\fR by a user with
858 \fB{PRIV_FILE_CHOWN_SELF}\fR privilege, and in particular on a system where
859 \fB{_POSIX_CHOWN_RESTRICTED}\fR is not in effect (effectively granting this
860 privilege to all users where not overridden), extracted or copied files can end
861 up with owners and groups determined by those of the original archived files,
862 which can differ from the invoking user's. This might not be what the user
863 intended. The \fB-R\fR option can be used to retain file ownership, if desired,
864 if you specify the user's id.
867 The inode number stored in the header (\fB/usr/include/archives.h\fR) is an
868 unsigned short, which is 2 bytes. This limits the range of inode numbers from
869 \fB0\fR to \fB65535\fR. Files which are hard linked must fall in this inode
870 range. This could be a problem when moving \fBcpio\fR archives between
871 different vendors' machines.
874 You must use the same blocking factor when you retrieve or copy files from the
875 tape to the hard disk as you did when you copied files from the hard disk to
876 the tape. Therefore, you must specify the \fB-B\fR or \fB-C\fR option.
879 During \fB-p\fR and \fB-o\fR processing, \fBcpio\fR buffers the file list
880 presented on stdin in a temporary file.
883 The new \fBpax\fR(1) format, with a command that supports it (for example,
884 \fBtar\fR), should be used for large files. The \fBcpio\fR command is no longer
885 part of the current POSIX standard and is deprecated in favor of \fBpax\fR.