Commit | Line | Data |
---|---|---|
ba5e8546 KB |
1 | .\" Copyright (c) 1989, 1990, 1993 |
2 | .\" The Regents of the University of California. All rights reserved. | |
c4c58dfe | 3 | .\" |
cf136d2c KB |
4 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" the Institute of Electrical and Electronics Engineers, Inc. | |
6 | .\" | |
c4a7b8ab | 7 | .\" %sccs.include.redist.roff% |
a783899b | 8 | .\" |
ba5e8546 | 9 | .\" @(#)cp.1 8.1 (Berkeley) %G% |
c4c58dfe | 10 | .\" |
b5dc1377 CL |
11 | .Dd |
12 | .Dt CP 1 | |
13 | .Os BSD 4 | |
14 | .Sh NAME | |
15 | .Nm cp | |
16 | .Nd copy files | |
17 | .Sh SYNOPSIS | |
18 | .Nm cp | |
04e69296 | 19 | .Op Fl HRfhip |
b5dc1377 | 20 | .Ar source_file target_file |
b5dc1377 | 21 | .Nm cp |
04e69296 | 22 | .Op Fl HRfhip |
b5dc1377 CL |
23 | .Ar source_file ... target_directory |
24 | .Sh DESCRIPTION | |
5325ced3 | 25 | In the first synopsis form, the |
b5dc1377 CL |
26 | .Nm cp |
27 | utility copies the contents of the | |
28 | .Ar source_file | |
29 | to the | |
5325ced3 CL |
30 | .Ar target_file . |
31 | In the second synopsis form, | |
b5dc1377 | 32 | the contents of each named |
5325ced3 | 33 | .Ar source_file |
b5dc1377 CL |
34 | is copied to the destination |
35 | .Ar target_directory . | |
36 | The names of the files themselves are not changed. | |
a783899b | 37 | If |
b5dc1377 | 38 | .Nm cp |
24e5a125 | 39 | detects an attempt to copy a file to itself, the copy will fail. |
5325ced3 | 40 | .Pp |
a783899b | 41 | The following options are available: |
c4a7b8ab | 42 | .Bl -tag -width flag |
04e69296 EA |
43 | .It Fl H |
44 | When encountering a symbolic link on the command line, follow it. All other | |
45 | symbolic links encountered in the traversal are not followed. | |
50e548fa EA |
46 | Provided for the |
47 | .Fl R | |
48 | option which does not follow symbolic links by default. | |
0e853b88 CL |
49 | .It Fl R |
50 | If | |
51 | .Ar source_file | |
52 | designates a directory, | |
53 | .Nm cp | |
54 | copies the directory and the entire subtree connected at that point. | |
55 | This option also causes symbolic links to be copied, rather than | |
56 | indirected through, and for | |
57 | .Nm cp | |
58 | to create special files rather than copying them as normal files. | |
59 | Created directories have the same mode as the corresponding source | |
60 | directory, unmodified by the process' umask. | |
61 | .It Fl f | |
5325ced3 CL |
62 | For each existing destination pathname, remove it and |
63 | create a new file, without prompting for confirmation | |
64 | regardless of its permissions. | |
65 | (The | |
66 | .Fl i | |
67 | option is ignored if the | |
68 | .Fl f | |
69 | option is specified.) | |
0e853b88 | 70 | .It Fl h |
04e69296 | 71 | When encountering a symbolic link anywhere in the traversal, follow it. |
24e5a125 | 72 | Provided for the |
3c3c3fc0 | 73 | .Fl R |
24e5a125 | 74 | option which does not follow symbolic links by default. |
0e853b88 | 75 | .It Fl i |
a783899b | 76 | Causes |
b5dc1377 | 77 | .Nm cp |
e8865dd0 | 78 | to write a prompt to the standard error output before copying a file that would |
a783899b | 79 | overwrite an existing file. |
5325ced3 CL |
80 | If the response from the standard input begins with the character |
81 | .Sq Li y , | |
82 | the file is copied if permissions allow the copy. | |
0e853b88 | 83 | .It Fl p |
a783899b | 84 | Causes |
b5dc1377 | 85 | .Nm cp |
a783899b | 86 | to preserve in the copy as many of the modification time, access time, |
a7b841a8 | 87 | file flags, file mode, user ID, and group ID as allowed by permissions. |
b5dc1377 | 88 | .Pp |
c942f008 KB |
89 | If the user ID and group ID cannot be preserved, no error message |
90 | is displayed and the exit value is not altered. | |
b5dc1377 | 91 | .Pp |
5325ced3 CL |
92 | If the source file has its set user ID bit on and the user ID cannot |
93 | be preserved, the set user ID bit is not preserved | |
94 | in the copy's permissions. | |
95 | If the source file has its set group ID bit on and the group ID cannot | |
96 | be preserved, the set group ID bit is not preserved | |
97 | in the copy's permissions. | |
e8865dd0 KM |
98 | If the source file has both its set user ID and set group ID bits on, |
99 | and either the user ID or group ID cannot be preserved, neither | |
5325ced3 CL |
100 | the set user ID or set group ID bits are preserved in the copy's |
101 | permissions. | |
0e853b88 | 102 | .El |
b5dc1377 CL |
103 | .Pp |
104 | For each destination file that already exists, its contents are | |
5325ced3 CL |
105 | overwritten if permissions allow, but its mode, user ID, and group |
106 | ID are unchanged. | |
b5dc1377 | 107 | .Pp |
feb92fe6 EA |
108 | In the second synopsis form, |
109 | .Ar target_directory | |
110 | must exist unless there is only one named | |
111 | .Ar source_file | |
112 | which is a directory and the | |
113 | .Fl R | |
114 | flag is specified. | |
115 | .Pp | |
b5dc1377 | 116 | If the destination file does not exist, the mode of the source file is |
5325ced3 | 117 | used as modified by the file mode creation mask |
c4a7b8ab | 118 | .Pf ( Ic umask , |
5325ced3 CL |
119 | see |
120 | .Xr csh 1 ) . | |
121 | If the source file has its set user ID bit on, that bit is removed | |
122 | unless both the source file and the destination file are owned by the | |
123 | same user. | |
124 | If the source file has its set group ID bit on, that bit is removed | |
125 | unless both the source file and the destination file are in the same | |
126 | group and the user is a member of that group. | |
127 | If both the set user ID and set group ID bits are set, all of the above | |
128 | conditions must be fulfilled or both bits are removed. | |
b5dc1377 CL |
129 | .Pp |
130 | Appropriate permissions are required for file creation or overwriting. | |
131 | .Pp | |
50e548fa EA |
132 | Symbolic links are always followed unless the |
133 | .Fl R | |
134 | flag is set in which case symbolic links are not followed by default. | |
135 | However, the | |
04e69296 EA |
136 | .Fl H |
137 | or | |
138 | .Fl h | |
50e548fa EA |
139 | flags (in conjuction with the |
140 | .Fl R | |
141 | flag) cause symbolic link following as detailed above. | |
5325ced3 | 142 | .Pp |
b5dc1377 | 143 | .Nm Cp |
a783899b | 144 | exits 0 on success, >0 if an error occurred. |
b5dc1377 CL |
145 | .Sh SEE ALSO |
146 | .Xr mv 1 , | |
147 | .Xr rcp 1 , | |
50e548fa | 148 | .Xr umask 2 , |
0d17b9a2 KB |
149 | .Xr fts 3 , |
150 | .Xr symlink 7 | |
b5dc1377 CL |
151 | .Sh HISTORY |
152 | The | |
153 | .Nm cp | |
c4a7b8ab CL |
154 | command is expected to be |
155 | .St -p1003.2 | |
156 | compatible. |