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