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