BSD 4_3_Reno release
[unix-history] / usr / src / bin / cp / cp.1
CommitLineData
b5dc1377 1.\" Copyright (c) 1989, 1990 The Regents of the University of California.
a783899b 2.\" All rights reserved.
c4c58dfe 3.\"
1c15e888
C
4.\" Redistribution and use in source and binary forms are permitted provided
5.\" that: (1) source distributions retain this entire copyright notice and
6.\" comment, and (2) distributions including binaries display the following
7.\" acknowledgement: ``This product includes software developed by the
8.\" University of California, Berkeley and its contributors'' in the
9.\" documentation or other materials provided with the distribution and in
10.\" all advertising materials mentioning features or use of this software.
11.\" Neither the name of the University nor the names of its contributors may
12.\" be used to endorse or promote products derived from this software without
13.\" specific prior written permission.
14.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
15.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
16.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
a783899b 17.\"
1c15e888 18.\" @(#)cp.1 6.11 (Berkeley) 7/24/90
c4c58dfe 19.\"
1c15e888 20.Dd July 24, 1990
b5dc1377
CL
21.Dt CP 1
22.Os BSD 4
23.Sh NAME
24.Nm cp
25.Nd copy files
26.Sh SYNOPSIS
27.Nm cp
5325ced3 28.Op Fl Rfhip
b5dc1377 29.Ar source_file target_file
b5dc1377 30.Nm cp
3c3c3fc0 31.Op Fl Rfhip
b5dc1377
CL
32.Ar source_file ... target_directory
33.Sh DESCRIPTION
5325ced3 34In the first synopsis form, the
b5dc1377
CL
35.Nm cp
36utility copies the contents of the
37.Ar source_file
38to the
5325ced3
CL
39.Ar target_file .
40In the second synopsis form,
b5dc1377 41the contents of each named
5325ced3 42.Ar source_file
b5dc1377
CL
43is copied to the destination
44.Ar target_directory .
45The names of the files themselves are not changed.
a783899b 46If
b5dc1377 47.Nm cp
24e5a125 48detects an attempt to copy a file to itself, the copy will fail.
5325ced3 49.Pp
a783899b 50The following options are available:
5325ced3
CL
51.Tw Ds
52.Tp Fl f
53For each existing destination pathname, remove it and
54create a new file, without prompting for confirmation
55regardless of its permissions.
56(The
57.Fl i
58option is ignored if the
59.Fl f
60option is specified.)
b5dc1377 61.Tp Fl h
a783899b 62Forces
b5dc1377 63.Nm cp
a783899b 64to follow symbolic links.
24e5a125 65Provided for the
3c3c3fc0 66.Fl R
24e5a125 67option which does not follow symbolic links by default.
b5dc1377 68.Tp Fl i
a783899b 69Causes
b5dc1377 70.Nm cp
a783899b
KB
71to write a prompt to standard error before copying a file that would
72overwrite an existing file.
5325ced3
CL
73If the response from the standard input begins with the character
74.Sq Li y ,
75the file is copied if permissions allow the copy.
b5dc1377 76.Tp Fl p
a783899b 77Causes
b5dc1377 78.Nm cp
a783899b
KB
79to preserve in the copy as many of the modification time, access time,
80file mode, user ID, and group ID as allowed by permissions.
b5dc1377 81.Pp
c942f008
KB
82If the user ID and group ID cannot be preserved, no error message
83is displayed and the exit value is not altered.
b5dc1377 84.Pp
5325ced3
CL
85If the source file has its set user ID bit on and the user ID cannot
86be preserved, the set user ID bit is not preserved
87in the copy's permissions.
88If the source file has its set group ID bit on and the group ID cannot
89be preserved, the set group ID bit is not preserved
90in the copy's permissions.
91If the source file has both the set user ID and set group ID bits
92on and either the user ID or group ID cannot be preserved, neither
93the set user ID or set group ID bits are preserved in the copy's
94permissions.
3c3c3fc0 95.Tp Fl R
a783899b 96If
b5dc1377 97.Ar source_file
a783899b 98designates a directory,
b5dc1377 99.Nm cp
a783899b 100copies the directory and the entire subtree connected at that point.
5325ced3
CL
101This option also causes symbolic links to be copied, rather than
102indirected through, and for
103.Nm cp
104to create special files rather than copying them as normal files.
24e5a125 105Created directories have the same mode as the corresponding source
5325ced3 106directory, unmodified by the process' umask.
b5dc1377
CL
107.Tp
108.Pp
109For each destination file that already exists, its contents are
5325ced3
CL
110overwritten if permissions allow, but its mode, user ID, and group
111ID are unchanged.
b5dc1377
CL
112.Pp
113If the destination file does not exist, the mode of the source file is
5325ced3
CL
114used as modified by the file mode creation mask
115.Pf \&( Ic umask ,
116see
117.Xr csh 1 ) .
118If the source file has its set user ID bit on, that bit is removed
119unless both the source file and the destination file are owned by the
120same user.
121If the source file has its set group ID bit on, that bit is removed
122unless both the source file and the destination file are in the same
123group and the user is a member of that group.
124If both the set user ID and set group ID bits are set, all of the above
125conditions must be fulfilled or both bits are removed.
b5dc1377
CL
126.Pp
127Appropriate permissions are required for file creation or overwriting.
128.Pp
5325ced3
CL
129Symbolic links are followed unless the
130.Fl R
131option is specified, in which case the link itself is copied.
132.Pp
b5dc1377 133.Nm Cp
a783899b 134exits 0 on success, >0 if an error occurred.
b5dc1377
CL
135.Sh SEE ALSO
136.Xr mv 1 ,
137.Xr rcp 1 ,
5325ced3
CL
138.Xr umask 2 ,
139.Xr csh 1
b5dc1377
CL
140.Sh HISTORY
141The
142.Nm cp
143command appeared in Version 6 AT&T UNIX.