Commit | Line | Data |
---|---|---|
b5dc1377 | 1 | .\" Copyright (c) 1989, 1990 The Regents of the University of California. |
a783899b | 2 | .\" All rights reserved. |
c4c58dfe | 3 | .\" |
27c71911 | 4 | .\" %sccs.include.redist.man% |
a783899b | 5 | .\" |
5325ced3 | 6 | .\" @(#)cp.1 6.11 (Berkeley) %G% |
c4c58dfe | 7 | .\" |
b5dc1377 CL |
8 | .Dd |
9 | .Dt CP 1 | |
10 | .Os BSD 4 | |
11 | .Sh NAME | |
12 | .Nm cp | |
13 | .Nd copy files | |
14 | .Sh SYNOPSIS | |
15 | .Nm cp | |
5325ced3 | 16 | .Op Fl Rfhip |
b5dc1377 | 17 | .Ar source_file target_file |
b5dc1377 | 18 | .Nm cp |
3c3c3fc0 | 19 | .Op Fl Rfhip |
b5dc1377 CL |
20 | .Ar source_file ... target_directory |
21 | .Sh DESCRIPTION | |
5325ced3 | 22 | In the first synopsis form, the |
b5dc1377 CL |
23 | .Nm cp |
24 | utility copies the contents of the | |
25 | .Ar source_file | |
26 | to the | |
5325ced3 CL |
27 | .Ar target_file . |
28 | In the second synopsis form, | |
b5dc1377 | 29 | the contents of each named |
5325ced3 | 30 | .Ar source_file |
b5dc1377 CL |
31 | is copied to the destination |
32 | .Ar target_directory . | |
33 | The names of the files themselves are not changed. | |
a783899b | 34 | If |
b5dc1377 | 35 | .Nm cp |
24e5a125 | 36 | detects an attempt to copy a file to itself, the copy will fail. |
5325ced3 | 37 | .Pp |
a783899b | 38 | The following options are available: |
5325ced3 CL |
39 | .Tw Ds |
40 | .Tp Fl f | |
41 | For each existing destination pathname, remove it and | |
42 | create a new file, without prompting for confirmation | |
43 | regardless of its permissions. | |
44 | (The | |
45 | .Fl i | |
46 | option is ignored if the | |
47 | .Fl f | |
48 | option is specified.) | |
b5dc1377 | 49 | .Tp Fl h |
a783899b | 50 | Forces |
b5dc1377 | 51 | .Nm cp |
a783899b | 52 | to follow symbolic links. |
24e5a125 | 53 | Provided for the |
3c3c3fc0 | 54 | .Fl R |
24e5a125 | 55 | option which does not follow symbolic links by default. |
b5dc1377 | 56 | .Tp Fl i |
a783899b | 57 | Causes |
b5dc1377 | 58 | .Nm cp |
a783899b KB |
59 | to write a prompt to standard error before copying a file that would |
60 | overwrite an existing file. | |
5325ced3 CL |
61 | If the response from the standard input begins with the character |
62 | .Sq Li y , | |
63 | the file is copied if permissions allow the copy. | |
b5dc1377 | 64 | .Tp Fl p |
a783899b | 65 | Causes |
b5dc1377 | 66 | .Nm cp |
a783899b KB |
67 | to preserve in the copy as many of the modification time, access time, |
68 | file mode, user ID, and group ID as allowed by permissions. | |
b5dc1377 | 69 | .Pp |
c942f008 KB |
70 | If the user ID and group ID cannot be preserved, no error message |
71 | is displayed and the exit value is not altered. | |
b5dc1377 | 72 | .Pp |
5325ced3 CL |
73 | If the source file has its set user ID bit on and the user ID cannot |
74 | be preserved, the set user ID bit is not preserved | |
75 | in the copy's permissions. | |
76 | If the source file has its set group ID bit on and the group ID cannot | |
77 | be preserved, the set group ID bit is not preserved | |
78 | in the copy's permissions. | |
79 | If the source file has both the set user ID and set group ID bits | |
80 | on and either the user ID or group ID cannot be preserved, neither | |
81 | the set user ID or set group ID bits are preserved in the copy's | |
82 | permissions. | |
3c3c3fc0 | 83 | .Tp Fl R |
a783899b | 84 | If |
b5dc1377 | 85 | .Ar source_file |
a783899b | 86 | designates a directory, |
b5dc1377 | 87 | .Nm cp |
a783899b | 88 | copies the directory and the entire subtree connected at that point. |
5325ced3 CL |
89 | This option also causes symbolic links to be copied, rather than |
90 | indirected through, and for | |
91 | .Nm cp | |
92 | to create special files rather than copying them as normal files. | |
24e5a125 | 93 | Created directories have the same mode as the corresponding source |
5325ced3 | 94 | directory, unmodified by the process' umask. |
b5dc1377 CL |
95 | .Tp |
96 | .Pp | |
97 | For each destination file that already exists, its contents are | |
5325ced3 CL |
98 | overwritten if permissions allow, but its mode, user ID, and group |
99 | ID are unchanged. | |
b5dc1377 CL |
100 | .Pp |
101 | If the destination file does not exist, the mode of the source file is | |
5325ced3 CL |
102 | used as modified by the file mode creation mask |
103 | .Pf \&( Ic umask , | |
104 | see | |
105 | .Xr csh 1 ) . | |
106 | If the source file has its set user ID bit on, that bit is removed | |
107 | unless both the source file and the destination file are owned by the | |
108 | same user. | |
109 | If the source file has its set group ID bit on, that bit is removed | |
110 | unless both the source file and the destination file are in the same | |
111 | group and the user is a member of that group. | |
112 | If both the set user ID and set group ID bits are set, all of the above | |
113 | conditions must be fulfilled or both bits are removed. | |
b5dc1377 CL |
114 | .Pp |
115 | Appropriate permissions are required for file creation or overwriting. | |
116 | .Pp | |
5325ced3 CL |
117 | Symbolic links are followed unless the |
118 | .Fl R | |
119 | option is specified, in which case the link itself is copied. | |
120 | .Pp | |
b5dc1377 | 121 | .Nm Cp |
a783899b | 122 | exits 0 on success, >0 if an error occurred. |
b5dc1377 CL |
123 | .Sh SEE ALSO |
124 | .Xr mv 1 , | |
125 | .Xr rcp 1 , | |
5325ced3 CL |
126 | .Xr umask 2 , |
127 | .Xr csh 1 | |
b5dc1377 CL |
128 | .Sh HISTORY |
129 | The | |
130 | .Nm cp | |
131 | command appeared in Version 6 AT&T UNIX. |