xref: /freebsd/bin/cp/cp.1 (revision 417ed37975261df51f61d13e179ad04d8f4839c7)
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.\"	$Id$
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 fip
51.Ar source_file target_file
52.Nm cp
53.Oo
54.Fl R
55.Op Fl H | Fl L | Fl P
56.Oc
57.Op Fl fip
58.Ar source_file ... target_directory
59.Sh DESCRIPTION
60In the first synopsis form, the
61.Nm cp
62utility copies the contents of the
63.Ar source_file
64to the
65.Ar target_file .
66In the second synopsis form,
67the contents of each named
68.Ar source_file
69is copied to the destination
70.Ar target_directory .
71The names of the files themselves are not changed.
72If
73.Nm cp
74detects an attempt to copy a file to itself, the copy will fail.
75.Pp
76The following options are available:
77.Bl -tag -width flag
78.It Fl H
79If the
80.Fl R
81option is specified, symbolic links on the command line are followed.
82(Symbolic links encountered in the tree traversal are not followed.)
83.It Fl L
84If the
85.Fl R
86option is specified, all symbolic links are followed.
87.It Fl P
88If the
89.Fl R
90option is specified, no symbolic links are followed.
91.It Fl R
92If
93.Ar source_file
94designates a directory,
95.Nm cp
96copies the directory and the entire subtree connected at that point.
97This option also causes symbolic links to be copied, rather than
98indirected through, and for
99.Nm cp
100to create special files rather than copying them as normal files.
101Created directories have the same mode as the corresponding source
102directory, unmodified by the process' umask.
103.It Fl f
104For each existing destination pathname, remove it and
105create a new file, without prompting for confirmation
106regardless of its permissions.
107(The
108.Fl i
109option is ignored if the
110.Fl f
111option is specified.)
112.It Fl i
113Causes
114.Nm cp
115to write a prompt to the standard error output before copying a file
116that would overwrite an existing file.
117If the response from the standard input begins with the character
118.Sq Li y ,
119the file copy is attempted.
120.It Fl p
121Causes
122.Nm cp
123to preserve in the copy as many of the modification time, access time,
124file flags, file mode, user ID, and group ID as allowed by permissions.
125.Pp
126If the user ID and group ID cannot be preserved, no error message
127is displayed and the exit value is not altered.
128.Pp
129If the source file has its set user ID bit on and the user ID cannot
130be preserved, the set user ID bit is not preserved
131in the copy's permissions.
132If the source file has its set group ID bit on and the group ID cannot
133be preserved, the set group ID bit is not preserved
134in the copy's permissions.
135If the source file has both its set user ID and set group ID bits on,
136and either the user ID or group ID cannot be preserved, neither
137the set user ID or set group ID bits are preserved in the copy's
138permissions.
139.El
140.Pp
141For each destination file that already exists, its contents are
142overwritten if permissions allow, but its mode, user ID, and group
143ID are unchanged.
144.Pp
145In the second synopsis form,
146.Ar target_directory
147must exist unless there is only one named
148.Ar source_file
149which is a directory and the
150.Fl R
151flag is specified.
152.Pp
153If the destination file does not exist, the mode of the source file is
154used as modified by the file mode creation mask
155.Pf ( Ic umask ,
156see
157.Xr csh 1 ) .
158If the source file has its set user ID bit on, that bit is removed
159unless both the source file and the destination file are owned by the
160same user.
161If the source file has its set group ID bit on, that bit is removed
162unless both the source file and the destination file are in the same
163group and the user is a member of that group.
164If both the set user ID and set group ID bits are set, all of the above
165conditions must be fulfilled or both bits are removed.
166.Pp
167Appropriate permissions are required for file creation or overwriting.
168.Pp
169Symbolic links are always followed unless the
170.Fl R
171flag is set, in which case symbolic links are not followed, by default.
172The
173.Fl H
174or
175.Fl L
176flags (in conjunction with the
177.Fl R
178flag) cause symbolic links to be followed as described above.
179The
180.Fl H ,
181.Fl L
182and
183.Fl P
184options are ignored unless the
185.Fl R
186option is specified.
187In addition, these options override each other and the
188command's actions are determined by the last one specified.
189.Pp
190.Nm Cp
191exits 0 on success, >0 if an error occurred.
192.Sh COMPATIBILITY
193Historic versions of the
194.Nm cp
195utility had a
196.Fl r
197option.
198This implementation supports that option, however, its use is strongly
199discouraged, as it does not correctly copy special files, symbolic links
200or fifo's.
201.Sh SEE ALSO
202.Xr mv 1 ,
203.Xr rcp 1 ,
204.Xr umask 2 ,
205.Xr fts 3 ,
206.Xr symlink 7
207.Sh HISTORY
208The
209.Nm cp
210command is expected to be
211.St -p1003.2
212compatible.
213