Commit | Line | Data |
---|---|---|
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 | 34 | In the first synopsis form, the |
b5dc1377 CL |
35 | .Nm cp |
36 | utility copies the contents of the | |
37 | .Ar source_file | |
38 | to the | |
5325ced3 CL |
39 | .Ar target_file . |
40 | In the second synopsis form, | |
b5dc1377 | 41 | the contents of each named |
5325ced3 | 42 | .Ar source_file |
b5dc1377 CL |
43 | is copied to the destination |
44 | .Ar target_directory . | |
45 | The names of the files themselves are not changed. | |
a783899b | 46 | If |
b5dc1377 | 47 | .Nm cp |
24e5a125 | 48 | detects an attempt to copy a file to itself, the copy will fail. |
5325ced3 | 49 | .Pp |
a783899b | 50 | The following options are available: |
5325ced3 CL |
51 | .Tw Ds |
52 | .Tp Fl f | |
53 | For each existing destination pathname, remove it and | |
54 | create a new file, without prompting for confirmation | |
55 | regardless of its permissions. | |
56 | (The | |
57 | .Fl i | |
58 | option is ignored if the | |
59 | .Fl f | |
60 | option is specified.) | |
b5dc1377 | 61 | .Tp Fl h |
a783899b | 62 | Forces |
b5dc1377 | 63 | .Nm cp |
a783899b | 64 | to follow symbolic links. |
24e5a125 | 65 | Provided for the |
3c3c3fc0 | 66 | .Fl R |
24e5a125 | 67 | option which does not follow symbolic links by default. |
b5dc1377 | 68 | .Tp Fl i |
a783899b | 69 | Causes |
b5dc1377 | 70 | .Nm cp |
a783899b KB |
71 | to write a prompt to standard error before copying a file that would |
72 | overwrite an existing file. | |
5325ced3 CL |
73 | If the response from the standard input begins with the character |
74 | .Sq Li y , | |
75 | the file is copied if permissions allow the copy. | |
b5dc1377 | 76 | .Tp Fl p |
a783899b | 77 | Causes |
b5dc1377 | 78 | .Nm cp |
a783899b KB |
79 | to preserve in the copy as many of the modification time, access time, |
80 | file mode, user ID, and group ID as allowed by permissions. | |
b5dc1377 | 81 | .Pp |
c942f008 KB |
82 | If the user ID and group ID cannot be preserved, no error message |
83 | is displayed and the exit value is not altered. | |
b5dc1377 | 84 | .Pp |
5325ced3 CL |
85 | If the source file has its set user ID bit on and the user ID cannot |
86 | be preserved, the set user ID bit is not preserved | |
87 | in the copy's permissions. | |
88 | If the source file has its set group ID bit on and the group ID cannot | |
89 | be preserved, the set group ID bit is not preserved | |
90 | in the copy's permissions. | |
91 | If the source file has both the set user ID and set group ID bits | |
92 | on and either the user ID or group ID cannot be preserved, neither | |
93 | the set user ID or set group ID bits are preserved in the copy's | |
94 | permissions. | |
3c3c3fc0 | 95 | .Tp Fl R |
a783899b | 96 | If |
b5dc1377 | 97 | .Ar source_file |
a783899b | 98 | designates a directory, |
b5dc1377 | 99 | .Nm cp |
a783899b | 100 | copies the directory and the entire subtree connected at that point. |
5325ced3 CL |
101 | This option also causes symbolic links to be copied, rather than |
102 | indirected through, and for | |
103 | .Nm cp | |
104 | to create special files rather than copying them as normal files. | |
24e5a125 | 105 | Created directories have the same mode as the corresponding source |
5325ced3 | 106 | directory, unmodified by the process' umask. |
b5dc1377 CL |
107 | .Tp |
108 | .Pp | |
109 | For each destination file that already exists, its contents are | |
5325ced3 CL |
110 | overwritten if permissions allow, but its mode, user ID, and group |
111 | ID are unchanged. | |
b5dc1377 CL |
112 | .Pp |
113 | If the destination file does not exist, the mode of the source file is | |
5325ced3 CL |
114 | used as modified by the file mode creation mask |
115 | .Pf \&( Ic umask , | |
116 | see | |
117 | .Xr csh 1 ) . | |
118 | If the source file has its set user ID bit on, that bit is removed | |
119 | unless both the source file and the destination file are owned by the | |
120 | same user. | |
121 | If the source file has its set group ID bit on, that bit is removed | |
122 | unless both the source file and the destination file are in the same | |
123 | group and the user is a member of that group. | |
124 | If both the set user ID and set group ID bits are set, all of the above | |
125 | conditions must be fulfilled or both bits are removed. | |
b5dc1377 CL |
126 | .Pp |
127 | Appropriate permissions are required for file creation or overwriting. | |
128 | .Pp | |
5325ced3 CL |
129 | Symbolic links are followed unless the |
130 | .Fl R | |
131 | option is specified, in which case the link itself is copied. | |
132 | .Pp | |
b5dc1377 | 133 | .Nm Cp |
a783899b | 134 | exits 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 |
141 | The | |
142 | .Nm cp | |
143 | command appeared in Version 6 AT&T UNIX. |