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