1CPIO(1) BSD General Commands Manual CPIO(1)
2
4 cpio — copy files to and from archives
5
7 cpio {-i} [options] [pattern ...] [< archive]
8 cpio {-o} [options] < name-list [> archive]
9 cpio {-p} [options] dest-dir < name-list
10
12 cpio copies files between archives and directories. This implementation
13 can extract from tar, pax, cpio, zip, jar, ar, and ISO 9660 cdrom images
14 and can create tar, pax, cpio, ar, and shar archives.
15
16 The first option to cpio is a mode indicator from the following list:
17 -i Input. Read an archive from standard input (unless overridden)
18 and extract the contents to disk or (if the -t option is speci‐
19 fied) list the contents to standard output. If one or more file
20 patterns are specified, only files matching one of the patterns
21 will be extracted.
22 -o Output. Read a list of filenames from standard input and produce
23 a new archive on standard output (unless overridden) containing
24 the specified items.
25 -p Pass-through. Read a list of filenames from standard input and
26 copy the files to the specified directory.
27
29 Unless specifically stated otherwise, options are applicable in all oper‐
30 ating modes.
31
32 -0, --null
33 Read filenames separated by NUL characters instead of newlines.
34 This is necessary if any of the filenames being read might con‐
35 tain newlines.
36
37 -A (o mode only) Append to the specified archive. (Not yet imple‐
38 mented.)
39
40 -a (o and p modes) Reset access times on files after they are read.
41
42 -B (o mode only) Block output to records of 5120 bytes.
43
44 -C size
45 (o mode only) Block output to records of size bytes.
46
47 -c (o mode only) Use the old POSIX portable character format.
48 Equivalent to --format odc.
49
50 -d, --make-directories
51 (i and p modes) Create directories as necessary.
52
53 -E file
54 (i mode only) Read list of file name patterns from file to list
55 and extract.
56
57 -F file, --file file
58 Read archive from or write archive to file.
59
60 -f pattern
61 (i mode only) Ignore files that match pattern.
62
63 -H format, --format format
64 (o mode only) Produce the output archive in the specified format.
65 Supported formats include:
66
67 cpio Synonym for odc.
68 newc The SVR4 portable cpio format.
69 odc The old POSIX.1 portable octet-oriented cpio format.
70 pax The POSIX.1 pax format, an extension of the ustar for‐
71 mat.
72 ustar The POSIX.1 tar format.
73
74 The default format is odc. See libarchive-formats(5) for more
75 complete information about the formats currently supported by the
76 underlying libarchive(3) library.
77
78 -h, --help
79 Print usage information.
80
81 -I file
82 Read archive from file.
83
84 -i, --extract
85 Input mode. See above for description.
86
87 --insecure
88 (i and p mode only) Disable security checks during extraction or
89 copying. This allows extraction via symbolic links and path
90 names containing ‘..’ in the name.
91
92 -J, --xz
93 (o mode only) Compress the file with xz-compatible compression
94 before writing it. In input mode, this option is ignored; xz
95 compression is recognized automatically on input.
96
97 -j Synonym for -y.
98
99 -L (o and p modes) All symbolic links will be followed. Normally,
100 symbolic links are archived and copied as symbolic links. With
101 this option, the target of the link will be archived or copied
102 instead.
103
104 -l, --link
105 (p mode only) Create links from the target directory to the orig‐
106 inal files, instead of copying.
107
108 --lrzip
109 (o mode only) Compress the resulting archive with lrzip(1). In
110 input mode, this option is ignored.
111
112 --lzma (o mode only) Compress the file with lzma-compatible compression
113 before writing it. In input mode, this option is ignored; lzma
114 compression is recognized automatically on input.
115
116 --lzop (o mode only) Compress the resulting archive with lzop(1). In
117 input mode, this option is ignored.
118
119 -m, --preserve-modification-time
120 (i and p modes) Set file modification time on created files to
121 match those in the source.
122
123 -n, --numeric-uid-gid
124 (i mode, only with -t) Display numeric uid and gid. By default,
125 cpio displays the user and group names when they are provided in
126 the archive, or looks up the user and group names in the system
127 password database.
128
129 --no-preserve-owner
130 (i mode only) Do not attempt to restore file ownership. This is
131 the default when run by non-root users.
132
133 -O file
134 Write archive to file.
135
136 -o, --create
137 Output mode. See above for description.
138
139 -p, --pass-through
140 Pass-through mode. See above for description.
141
142 --preserve-owner
143 (i mode only) Restore file ownership. This is the default when
144 run by the root user.
145
146 --quiet
147 Suppress unnecessary messages.
148
149 -R [user][:][group], --owner [user][:][group]
150 Set the owner and/or group on files in the output. If group is
151 specified with no user (for example, -R :wheel) then the group
152 will be set but not the user. If the user is specified with a
153 trailing colon and no group (for example, -R root:) then the
154 group will be set to the user's default group. If the user is
155 specified with no trailing colon, then the user will be set but
156 not the group. In -i and -p modes, this option can only be used
157 by the super-user. (For compatibility, a period can be used in
158 place of the colon.)
159
160 -r (All modes.) Rename files interactively. For each file, a
161 prompt is written to /dev/tty containing the name of the file and
162 a line is read from /dev/tty. If the line read is blank, the
163 file is skipped. If the line contains a single period, the file
164 is processed normally. Otherwise, the line is taken to be the
165 new name of the file.
166
167 -t, --list
168 (i mode only) List the contents of the archive to stdout; do not
169 restore the contents to disk.
170
171 -u, --unconditional
172 (i and p modes) Unconditionally overwrite existing files. Ordi‐
173 narily, an older file will not overwrite a newer file on disk.
174
175 -V, --dot
176 Print a dot to stderr for each file as it is processed. Super‐
177 seded by -v.
178
179 -v, --verbose
180 Print the name of each file to stderr as it is processed. With
181 -t, provide a detailed listing of each file.
182
183 --version
184 Print the program version information and exit.
185
186 -y (o mode only) Compress the archive with bzip2-compatible compres‐
187 sion before writing it. In input mode, this option is ignored;
188 bzip2 compression is recognized automatically on input.
189
190 -Z (o mode only) Compress the archive with compress-compatible com‐
191 pression before writing it. In input mode, this option is
192 ignored; compression is recognized automatically on input.
193
194 -z (o mode only) Compress the archive with gzip-compatible compres‐
195 sion before writing it. In input mode, this option is ignored;
196 gzip compression is recognized automatically on input.
197
199 The cpio utility exits 0 on success, and >0 if an error occurs.
200
202 The following environment variables affect the execution of cpio:
203
204 LANG The locale to use. See environ(7) for more information.
205
206 TZ The timezone to use when displaying dates. See environ(7) for
207 more information.
208
210 The cpio command is traditionally used to copy file hierarchies in con‐
211 junction with the find(1) command. The first example here simply copies
212 all files from src to dest:
213 find src | cpio -pmud dest
214
215 By carefully selecting options to the find(1) command and combining it
216 with other standard utilities, it is possible to exercise very fine con‐
217 trol over which files are copied. This next example copies files from
218 src to dest that are more than 2 days old and whose names match a partic‐
219 ular pattern:
220 find src -mtime +2 | grep foo[bar] | cpio -pdmu dest
221
222 This example copies files from src to dest that are more than 2 days old
223 and which contain the word “foobar”:
224 find src -mtime +2 | xargs grep -l foobar | cpio -pdmu dest
225
227 The mode options i, o, and p and the options a, B, c, d, f, l, m, r, t,
228 u, and v comply with SUSv2.
229
230 The old POSIX.1 standard specified that only -i, -o, and -p were inter‐
231 preted as command-line options. Each took a single argument of a list of
232 modifier characters. For example, the standard syntax allows -imu but
233 does not support -miu or -i -m -u, since m and u are only modifiers to
234 -i, they are not command-line options in their own right. The syntax
235 supported by this implementation is backwards-compatible with the stan‐
236 dard. For best compatibility, scripts should limit themselves to the
237 standard syntax.
238
240 bzip2(1), tar(1), gzip(1), mt(1), pax(1), libarchive(3), cpio(5),
241 libarchive-formats(5), tar(5)
242
244 There is no current POSIX standard for the cpio command; it appeared in
245 ISO/IEC 9945-1:1996 (“POSIX.1”) but was dropped from IEEE Std 1003.1-2001
246 (“POSIX.1”).
247
248 The cpio, ustar, and pax interchange file formats are defined by IEEE Std
249 1003.1-2001 (“POSIX.1”) for the pax command.
250
252 The original cpio and find utilities were written by Dick Haight while
253 working in AT&T's Unix Support Group. They first appeared in 1977 in
254 PWB/UNIX 1.0, the “Programmer's Work Bench” system developed for use
255 within AT&T. They were first released outside of AT&T as part of System
256 III Unix in 1981. As a result, cpio actually predates tar, even though
257 it was not well-known outside of AT&T until some time later.
258
259 This is a complete re-implementation based on the libarchive(3) library.
260
262 The cpio archive format has several basic limitations: It does not store
263 user and group names, only numbers. As a result, it cannot be reliably
264 used to transfer files between systems with dissimilar user and group
265 numbering. Older cpio formats limit the user and group numbers to 16 or
266 18 bits, which is insufficient for modern systems. The cpio archive for‐
267 mats cannot support files over 4 gigabytes, except for the “odc” variant,
268 which can support files up to 8 gigabytes.
269
270BSD October 7, 2012 BSD