This commit was generated by cvs2svn to track changes on a CVS vendor
[unix-history] / bin / cp / cp.1
CommitLineData
15637ed4
RG
1.\" Copyright (c) 1989, 1990 The Regents of the University of California.
2.\" 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 6.15 (Berkeley) 7/30/91
36.\"
37.Dd July 30, 1991
38.Dt CP 1
39.Os BSD 4
40.Sh NAME
41.Nm cp
42.Nd copy files
43.Sh SYNOPSIS
44.Nm cp
45.Op Fl Rfhip
46.Ar source_file target_file
47.Nm cp
48.Op Fl Rfhip
49.Ar source_file ... target_directory
50.Sh DESCRIPTION
51In the first synopsis form, the
52.Nm cp
53utility copies the contents of the
54.Ar source_file
55to the
56.Ar target_file .
57In the second synopsis form,
58the contents of each named
59.Ar source_file
60is copied to the destination
61.Ar target_directory .
62The names of the files themselves are not changed.
63If
64.Nm cp
65detects an attempt to copy a file to itself, the copy will fail.
66.Pp
67The following options are available:
68.Bl -tag -width flag
69.It Fl R
70If
71.Ar source_file
72designates a directory,
73.Nm cp
74copies the directory and the entire subtree connected at that point.
75This option also causes symbolic links to be copied, rather than
76indirected through, and for
77.Nm cp
78to create special files rather than copying them as normal files.
79Created directories have the same mode as the corresponding source
80directory, unmodified by the process' umask.
81.It Fl f
82For each existing destination pathname, remove it and
83create a new file, without prompting for confirmation
84regardless of its permissions.
85(The
86.Fl i
87option is ignored if the
88.Fl f
89option is specified.)
90.It Fl h
91Forces
92.Nm cp
93to follow symbolic links.
94Provided for the
95.Fl R
96option which does not follow symbolic links by default.
97.It Fl i
98Causes
99.Nm cp
100to write a prompt to standard error before copying a file that would
101overwrite an existing file.
102If the response from the standard input begins with the character
103.Sq Li y ,
104the file is copied if permissions allow the copy.
105.It Fl p
106Causes
107.Nm cp
108to preserve in the copy as many of the modification time, access time,
109file mode, user ID, and group ID as allowed by permissions.
110.Pp
111If the user ID and group ID cannot be preserved, no error message
112is displayed and the exit value is not altered.
113.Pp
114If the source file has its set user ID bit on and the user ID cannot
115be preserved, the set user ID bit is not preserved
116in the copy's permissions.
117If the source file has its set group ID bit on and the group ID cannot
118be preserved, the set group ID bit is not preserved
119in the copy's permissions.
120If the source file has both the set user ID and set group ID bits
121on and either the user ID or group ID cannot be preserved, neither
122the set user ID or set group ID bits are preserved in the copy's
123permissions.
124.El
125.Pp
126For each destination file that already exists, its contents are
127overwritten if permissions allow, but its mode, user ID, and group
128ID are unchanged.
129.Pp
130If the destination file does not exist, the mode of the source file is
131used as modified by the file mode creation mask
132.Pf ( Ic umask ,
133see
134.Xr csh 1 ) .
135If the source file has its set user ID bit on, that bit is removed
136unless both the source file and the destination file are owned by the
137same user.
138If the source file has its set group ID bit on, that bit is removed
139unless both the source file and the destination file are in the same
140group and the user is a member of that group.
141If both the set user ID and set group ID bits are set, all of the above
142conditions must be fulfilled or both bits are removed.
143.Pp
144Appropriate permissions are required for file creation or overwriting.
145.Pp
146Symbolic links are followed unless the
147.Fl R
148option is specified, in which case the link itself is copied.
149.Pp
150.Nm Cp
151exits 0 on success, >0 if an error occurred.
152.Sh SEE ALSO
153.Xr mv 1 ,
154.Xr rcp 1 ,
155.Xr umask 2
156.Sh HISTORY
157The
158.Nm cp
159command is expected to be
160.St -p1003.2
161compatible.