xref: /freebsd/bin/cp/cp.1 (revision 2357939bc239bd5334a169b62313806178dd8f30)
1.\" Copyright (c) 1989, 1990, 1993, 1994
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the Institute of Electrical and Electronics Engineers, Inc.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 4. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"	@(#)cp.1	8.3 (Berkeley) 4/18/94
32.\" $FreeBSD$
33.\"
34.Dd July 23, 2002
35.Dt CP 1
36.Os
37.Sh NAME
38.Nm cp
39.Nd copy files
40.Sh SYNOPSIS
41.Nm
42.Oo
43.Fl R
44.Op Fl H | Fl L | Fl P
45.Oc
46.Op Fl f | i | n
47.Op Fl pv
48.Ar source_file target_file
49.Nm
50.Oo
51.Fl R
52.Op Fl H | Fl L | Fl P
53.Oc
54.Op Fl f | i | n
55.Op Fl pv
56.Ar source_file ... target_directory
57.Sh DESCRIPTION
58In the first synopsis form, the
59.Nm
60utility copies the contents of the
61.Ar source_file
62to the
63.Ar target_file .
64In the second synopsis form,
65the contents of each named
66.Ar source_file
67is copied to the destination
68.Ar target_directory .
69The names of the files themselves are not changed.
70If
71.Nm
72detects an attempt to copy a file to itself, the copy will fail.
73.Pp
74The following options are available:
75.Bl -tag -width flag
76.It Fl H
77If the
78.Fl R
79option is specified, symbolic links on the command line are followed.
80(Symbolic links encountered in the tree traversal are not followed.)
81.It Fl L
82If the
83.Fl R
84option is specified, all symbolic links are followed.
85.It Fl P
86If the
87.Fl R
88option is specified, no symbolic links are followed.
89This is the default.
90.It Fl R
91If
92.Ar source_file
93designates a directory,
94.Nm
95copies the directory and the entire subtree connected at that point.
96This option also causes symbolic links to be copied, rather than
97indirected through, and for
98.Nm
99to create special files rather than copying them as normal files.
100Created directories have the same mode as the corresponding source
101directory, unmodified by the process' umask.
102.Pp
103Note that
104.Nm
105copies hard linked files as separate files.
106If you need to preserve hard links, consider using
107.Xr tar 1 ,
108.Xr cpio 1 ,
109or
110.Xr pax 1
111instead.
112.It Fl f
113For each existing destination pathname, remove it and
114create a new file, without prompting for confirmation
115regardless of its permissions.
116(The
117.Fl f
118option overrides any previous
119.Fl i
120or
121.Fl n
122options.)
123.It Fl i
124Cause
125.Nm
126to write a prompt to the standard error output before copying a file
127that would overwrite an existing file.
128If the response from the standard input begins with the character
129.Sq Li y
130or
131.Sq Li Y ,
132the file copy is attempted.
133(The
134.Fl i
135option overrides any previous
136.Fl f
137or
138.Fl n
139options.)
140.It Fl n
141Do not overwrite an existing file.
142(The
143.Fl n
144option overrides any previous
145.Fl f
146or
147.Fl i
148options.)
149.It Fl p
150Cause
151.Nm
152to preserve the following attributes of each source
153file in the copy: modification time, access time,
154file flags, file mode, user ID, and group ID, as allowed by permissions.
155.Pp
156If the user ID and group ID cannot be preserved, no error message
157is displayed and the exit value is not altered.
158.Pp
159If the source file has its set-user-ID bit on and the user ID cannot
160be preserved, the set-user-ID bit is not preserved
161in the copy's permissions.
162If the source file has its set-group-ID bit on and the group ID cannot
163be preserved, the set-group-ID bit is not preserved
164in the copy's permissions.
165If the source file has both its set-user-ID and set-group-ID bits on,
166and either the user ID or group ID cannot be preserved, neither
167the set-user-ID nor set-group-ID bits are preserved in the copy's
168permissions.
169.It Fl v
170Cause
171.Nm
172to be verbose, showing files as they are copied.
173.El
174.Pp
175For each destination file that already exists, its contents are
176overwritten if permissions allow.  Its mode, user ID, and group
177ID are unchanged unless the
178.Fl p
179option was specified.
180.Pp
181In the second synopsis form,
182.Ar target_directory
183must exist unless there is only one named
184.Ar source_file
185which is a directory and the
186.Fl R
187flag is specified.
188.Pp
189If the destination file does not exist, the mode of the source file is
190used as modified by the file mode creation mask
191.Pf ( Ic umask ,
192see
193.Xr csh 1 ) .
194If the source file has its set-user-ID bit on, that bit is removed
195unless both the source file and the destination file are owned by the
196same user.
197If the source file has its set-group-ID bit on, that bit is removed
198unless both the source file and the destination file are in the same
199group and the user is a member of that group.
200If both the set-user-ID and set-group-ID bits are set, all of the above
201conditions must be fulfilled or both bits are removed.
202.Pp
203Appropriate permissions are required for file creation or overwriting.
204.Pp
205Symbolic links are always followed unless the
206.Fl R
207flag is set, in which case symbolic links are not followed, by default.
208The
209.Fl H
210or
211.Fl L
212flags (in conjunction with the
213.Fl R
214flag) cause symbolic links to be followed as described above.
215The
216.Fl H ,
217.Fl L
218and
219.Fl P
220options are ignored unless the
221.Fl R
222option is specified.
223In addition, these options override each other and the
224command's actions are determined by the last one specified.
225.Pp
226If
227.Nm
228receives a
229.Dv SIGINFO
230(see the
231.Cm status
232argument for
233.Xr stty 1 )
234signal, the current input and output file and the percentage complete
235will be written to the standard output.
236.Sh DIAGNOSTICS
237.Ex -std
238.Sh COMPATIBILITY
239Historic versions of the
240.Nm
241utility had a
242.Fl r
243option.
244This implementation supports that option, however, its use is strongly
245discouraged, as it does not correctly copy special files, symbolic links
246or fifo's.
247.Pp
248The
249.Fl v
250and
251.Fl n
252options are non-standard and their use in scripts is not recommended.
253.Sh SEE ALSO
254.Xr mv 1 ,
255.Xr rcp 1 ,
256.Xr umask 2 ,
257.Xr fts 3 ,
258.Xr symlink 7
259.Sh STANDARDS
260The
261.Nm
262command is expected to be
263.St -p1003.2
264compatible.
265.Sh HISTORY
266A
267.Nm
268command appeared in
269.At v1 .
270