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