xref: /freebsd/contrib/libarchive/cpio/bsdcpio.1 (revision 20f8619da05e2775ef7b381c5df080d621fa8332)
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 and path names containing
160.Sq ..
161in the name.
162.It Fl J , Fl Fl xz
163(o mode only)
164Compress the file with xz-compatible compression before writing it.
165In input mode, this option is ignored; xz compression is recognized
166automatically on input.
167.It Fl j
168Synonym for
169.Fl y .
170.It Fl L
171(o and p modes)
172All symbolic links will be followed.
173Normally, symbolic links are archived and copied as symbolic links.
174With this option, the target of the link will be archived or copied instead.
175.It Fl l , Fl Fl link
176(p mode only)
177Create links from the target directory to the original files,
178instead of copying.
179.It Fl Fl lrzip
180(o mode only)
181Compress the resulting archive with
182.Xr lrzip 1 .
183In input mode, this option is ignored.
184.It Fl Fl lz4
185(o mode only)
186Compress the archive with lz4-compatible compression before writing it.
187In input mode, this option is ignored; lz4 compression is recognized
188automatically on input.
189.It Fl Fl lzma
190(o mode only)
191Compress the file with lzma-compatible compression before writing it.
192In input mode, this option is ignored; lzma compression is recognized
193automatically on input.
194.It Fl Fl lzop
195(o mode only)
196Compress the resulting archive with
197.Xr lzop 1 .
198In input mode, this option is ignored.
199.It Fl Fl passphrase Ar passphrase
200The
201.Pa passphrase
202is used to extract or create an encrypted archive.
203Currently, zip is only a format that
204.Nm
205can handle encrypted archives.
206You shouldn't use this option unless you realize how insecure
207use of this option is.
208.It Fl m , Fl Fl preserve-modification-time
209(i and p modes)
210Set file modification time on created files to match
211those in the source.
212.It Fl n , Fl Fl numeric-uid-gid
213(i mode, only with
214.Fl t )
215Display numeric uid and gid.
216By default,
217.Nm
218displays the user and group names when they are provided in the
219archive, or looks up the user and group names in the system
220password database.
221.It Fl Fl no-preserve-owner
222(i mode only)
223Do not attempt to restore file ownership.
224This is the default when run by non-root users.
225.It Fl O Ar file
226Write archive to
227.Ar file .
228.It Fl o , Fl Fl create
229Output mode.
230See above for description.
231.It Fl p , Fl Fl pass-through
232Pass-through mode.
233See above for description.
234.It Fl Fl preserve-owner
235(i mode only)
236Restore file ownership.
237This is the default when run by the root user.
238.It Fl Fl quiet
239Suppress unnecessary messages.
240.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
241Set the owner and/or group on files in the output.
242If group is specified with no user
243(for example,
244.Fl R Ar :wheel )
245then the group will be set but not the user.
246If the user is specified with a trailing colon and no group
247(for example,
248.Fl R Ar root: )
249then the group will be set to the user's default group.
250If the user is specified with no trailing colon, then
251the user will be set but not the group.
252In
253.Fl i
254and
255.Fl p
256modes, this option can only be used by the super-user.
257(For compatibility, a period can be used in place of the colon.)
258.It Fl r
259(All modes.)
260Rename files interactively.
261For each file, a prompt is written to
262.Pa /dev/tty
263containing the name of the file and a line is read from
264.Pa /dev/tty .
265If the line read is blank, the file is skipped.
266If the line contains a single period, the file is processed normally.
267Otherwise, the line is taken to be the new name of the file.
268.It Fl t , Fl Fl list
269(i mode only)
270List the contents of the archive to stdout;
271do not restore the contents to disk.
272.It Fl u , Fl Fl unconditional
273(i and p modes)
274Unconditionally overwrite existing files.
275Ordinarily, an older file will not overwrite a newer file on disk.
276.It Fl V , Fl Fl dot
277Print a dot to stderr for each file as it is processed.
278Superseded by
279.Fl v .
280.It Fl v , Fl Fl verbose
281Print the name of each file to stderr as it is processed.
282With
283.Fl t ,
284provide a detailed listing of each file.
285.It Fl Fl version
286Print the program version information and exit.
287.It Fl y
288(o mode only)
289Compress the archive with bzip2-compatible compression before writing it.
290In input mode, this option is ignored;
291bzip2 compression is recognized automatically on input.
292.It Fl Z
293(o mode only)
294Compress the archive with compress-compatible compression before writing it.
295In input mode, this option is ignored;
296compression is recognized automatically on input.
297.It Fl z
298(o mode only)
299Compress the archive with gzip-compatible compression before writing it.
300In input mode, this option is ignored;
301gzip compression is recognized automatically on input.
302.El
303.Sh EXIT STATUS
304.Ex -std
305.Sh ENVIRONMENT
306The following environment variables affect the execution of
307.Nm :
308.Bl -tag -width ".Ev BLOCKSIZE"
309.It Ev LANG
310The locale to use.
311See
312.Xr environ 7
313for more information.
314.It Ev TZ
315The timezone to use when displaying dates.
316See
317.Xr environ 7
318for more information.
319.El
320.Sh EXAMPLES
321The
322.Nm
323command is traditionally used to copy file hierarchies in conjunction
324with the
325.Xr find 1
326command.
327The first example here simply copies all files from
328.Pa src
329to
330.Pa dest :
331.Dl Nm find Pa src | Nm Fl pmud Pa dest
332.Pp
333By carefully selecting options to the
334.Xr find 1
335command and combining it with other standard utilities,
336it is possible to exercise very fine control over which files are copied.
337This next example copies files from
338.Pa src
339to
340.Pa dest
341that are more than 2 days old and whose names match a particular pattern:
342.Dl Nm find Pa src Fl mtime Ar +2 | Nm grep foo[bar] | Nm Fl pdmu Pa dest
343.Pp
344This example copies files from
345.Pa src
346to
347.Pa dest
348that are more than 2 days old and which contain the word
349.Do foobar Dc :
350.Dl Nm find Pa src Fl mtime Ar +2 | Nm xargs Nm grep -l foobar | Nm Fl pdmu Pa dest
351.Sh COMPATIBILITY
352The mode options i, o, and p and the options
353a, B, c, d, f, l, m, r, t, u, and v comply with SUSv2.
354.Pp
355The old POSIX.1 standard specified that only
356.Fl i ,
357.Fl o ,
358and
359.Fl p
360were interpreted as command-line options.
361Each took a single argument of a list of modifier
362characters.
363For example, the standard syntax allows
364.Fl imu
365but does not support
366.Fl miu
367or
368.Fl i Fl m Fl u ,
369since
370.Ar m
371and
372.Ar u
373are only modifiers to
374.Fl i ,
375they are not command-line options in their own right.
376The syntax supported by this implementation is backwards-compatible
377with the standard.
378For best compatibility, scripts should limit themselves to the
379standard syntax.
380.Sh SEE ALSO
381.Xr bzip2 1 ,
382.Xr tar 1 ,
383.Xr gzip 1 ,
384.Xr mt 1 ,
385.Xr pax 1 ,
386.Xr libarchive 3 ,
387.Xr cpio 5 ,
388.Xr libarchive-formats 5 ,
389.Xr tar 5
390.Sh STANDARDS
391There is no current POSIX standard for the cpio command; it appeared
392in
393.St -p1003.1-96
394but was dropped from
395.St -p1003.1-2001 .
396.Pp
397The cpio, ustar, and pax interchange file formats are defined by
398.St -p1003.1-2001
399for the pax command.
400.Sh HISTORY
401The original
402.Nm cpio
403and
404.Nm find
405utilities were written by Dick Haight
406while working in AT&T's Unix Support Group.
407They first appeared in 1977 in PWB/UNIX 1.0, the
408.Dq Programmer's Work Bench
409system developed for use within AT&T.
410They were first released outside of AT&T as part of System III Unix in 1981.
411As a result,
412.Nm cpio
413actually predates
414.Nm tar ,
415even though it was not well-known outside of AT&T until some time later.
416.Pp
417This is a complete re-implementation based on the
418.Xr libarchive 3
419library.
420.Sh BUGS
421The cpio archive format has several basic limitations:
422It does not store user and group names, only numbers.
423As a result, it cannot be reliably used to transfer
424files between systems with dissimilar user and group numbering.
425Older cpio formats limit the user and group numbers to
42616 or 18 bits, which is insufficient for modern systems.
427The cpio archive formats cannot support files over 4 gigabytes,
428except for the
429.Dq odc
430variant, which can support files up to 8 gigabytes.
431