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