xref: /freebsd/bin/cp/cp.1 (revision f0adf7f5cdd241db2f2c817683191a6ef64a4e95)
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.
177Its mode, user ID, and group
178ID are unchanged unless the
179.Fl p
180option was specified.
181.Pp
182In the second synopsis form,
183.Ar target_directory
184must exist unless there is only one named
185.Ar source_file
186which is a directory and the
187.Fl R
188flag is specified.
189.Pp
190If the destination file does not exist, the mode of the source file is
191used as modified by the file mode creation mask
192.Pf ( Ic umask ,
193see
194.Xr csh 1 ) .
195If the source file has its set-user-ID bit on, that bit is removed
196unless both the source file and the destination file are owned by the
197same user.
198If the source file has its set-group-ID bit on, that bit is removed
199unless both the source file and the destination file are in the same
200group and the user is a member of that group.
201If both the set-user-ID and set-group-ID bits are set, all of the above
202conditions must be fulfilled or both bits are removed.
203.Pp
204Appropriate permissions are required for file creation or overwriting.
205.Pp
206Symbolic links are always followed unless the
207.Fl R
208flag is set, in which case symbolic links are not followed, by default.
209The
210.Fl H
211or
212.Fl L
213flags (in conjunction with the
214.Fl R
215flag) cause symbolic links to be followed as described above.
216The
217.Fl H ,
218.Fl L
219and
220.Fl P
221options are ignored unless the
222.Fl R
223option is specified.
224In addition, these options override each other and the
225command's actions are determined by the last one specified.
226.Pp
227If
228.Nm
229receives a
230.Dv SIGINFO
231(see the
232.Cm status
233argument for
234.Xr stty 1 )
235signal, the current input and output file and the percentage complete
236will be written to the standard output.
237.Sh DIAGNOSTICS
238.Ex -std
239.Sh COMPATIBILITY
240Historic versions of the
241.Nm
242utility had a
243.Fl r
244option.
245This implementation supports that option, however, its use is strongly
246discouraged, as it does not correctly copy special files, symbolic links
247or fifo's.
248.Pp
249The
250.Fl v
251and
252.Fl n
253options are non-standard and their use in scripts is not recommended.
254.Sh SEE ALSO
255.Xr mv 1 ,
256.Xr rcp 1 ,
257.Xr umask 2 ,
258.Xr fts 3 ,
259.Xr symlink 7
260.Sh STANDARDS
261The
262.Nm
263command is expected to be
264.St -p1003.2
265compatible.
266.Sh HISTORY
267A
268.Nm
269command appeared in
270.At v1 .
271