28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1989 AT&T
44 .\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved
45 .\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved
46 .\" Copyright 2013 Nexenta Systems, Inc. All rights reserved.
47 .\"
48 .TH CP 1 "Apr 15, 2013"
49 .SH NAME
50 cp \- copy files
51 .SH SYNOPSIS
52 .LP
53 .nf
54 \fB/usr/bin/cp\fR [\fB-afip@/\fR] \fIsource_file\fR \fItarget_file\fR
55 .fi
56
57 .LP
58 .nf
59 \fB/usr/bin/cp\fR [\fB-afip@/\fR] \fIsource_file\fR... \fItarget\fR
60 .fi
61
62 .LP
63 .nf
64 \fB/usr/bin/cp\fR [\fB-r\fR | \fB-R\fR [\fB-H\fR | \fB-L\fR | \fB-P\fR]] [\fB-afip@/\fR] \fIsource_dir\fR... \fItarget\fR
65 .fi
66
67 .LP
68 .nf
69 \fB/usr/bin/cp\fR [\fB-R\fR | \fB-R\fR [\fB-H\fR | \fB-L\fR | \fB-P\fR]] [\fB-afip@/\fR] \fIsource_dir\fR... \fItarget\fR
70 .fi
71
72 .LP
73 .nf
74 \fB/usr/xpg4/bin/cp\fR [\fB-afip@/\fR] \fIsource_file\fR \fItarget_file\fR
75 .fi
76
77 .LP
78 .nf
79 \fB/usr/xpg4/bin/cp\fR [\fB-afip@/\fR] \fIsource_file\fR... \fItarget\fR
80 .fi
81
82 .LP
83 .nf
84 \fB/usr/xpg4/bin/cp\fR [\fB-r\fR | \fB-R\fR [\fB-H\fR | \fB-L\fR | \fB-P\fR]] [\fB-afip@/\fR] \fIsource_dir\fR... \fItarget\fR
85 .fi
86
87 .LP
88 .nf
89 \fB/usr/xpg4/bin/cp\fR [\fB-R\fR | \fB-R\fR [\fB-H\fR | \fB-L\fR | \fB-P\fR]] [\fB-afip@/\fR] \fIsource_dir\fR... \fItarget\fR
90 .fi
91
92 .SH DESCRIPTION
93 .sp
94 .LP
95 In the first synopsis form, neither \fIsource_file\fR nor \fItarget_file\fR are
96 directory files, nor can they have the same name. The \fBcp\fR utility copies
97 the contents of \fIsource_file\fR to the destination path named by
98 \fItarget_file\fR. If \fItarget_file\fR exists, \fBcp\fR overwrites its
99 contents, but the mode (and \fBACL\fR if applicable), owner, and group
100 associated with it are not changed. The last modification time of
101 \fItarget_file\fR and the last access time of \fIsource_file\fR are set to the
102 time the copy was made. If \fItarget_file\fR does not exist, \fBcp\fR creates a
103 new file named \fItarget_file\fR that has the same mode as \fIsource_file\fR
104 except that the sticky bit is not set unless the user is super-user. In this
105 case, the owner and group of \fItarget_file\fR are those of the user, unless
106 the setgid bit is set on the directory containing the newly created file. If
107 the directory's setgid bit is set, the newly created file has the group of the
108 containing directory rather than of the creating user. If \fItarget_file\fR is
109 a link to another file, \fBcp\fR overwrites the link destination with the
110 contents of \fIsource_file\fR; the link(s) from \fItarget_file\fR remains.
111 .sp
112 .LP
113 In the second synopsis form, one or more \fIsource_file\fRs are copied to the
114 directory specified by \fItarget\fR. It is an error if any \fIsource_file\fR is
115 a file of type directory, if \fItarget\fR either does not exist or is not a
116 directory.
117 .sp
118 .LP
119 In the third or fourth synopsis forms, one or more directories specified by
120 \fIsource_dir\fR are copied to the directory specified by \fItarget\fR. Either
121 the \fB-r\fR or \fB-R\fR must be specified. For each \fIsource_dir\fR, \fBcp\fR
122 copies all files and subdirectories.
123 .SH OPTIONS
124 .sp
125 .LP
126 The following options are supported for both \fB/usr/bin/cp\fR and
127 \fB/usr/xpg4/bin/cp\fR:
128 .sp
129 .ne 2
130 .na
131 \fB\fB-a\fR\fR
132 .ad
133 .RS 6n
134 Archive mode. Same as -RpP.
135 .RE
136
137 .sp
138 .ne 2
139 .na
140 \fB\fB-f\fR\fR
141 .ad
142 .RS 6n
143 Unlink. If a file descriptor for a destination file cannot be obtained, this
144 option attempts to unlink the destination file and proceed.
145 .RE
255 .ne 2
256 .na
257 \fB\fB-/\fR\fR
258 .ad
259 .RS 6n
260 Preserves extended attributes and extended system attributes. Along with the
261 file's data, the \fBcp\fR utility attempts to copy extended attributes and
262 extended system attributes from each source file, and extended system
263 attributes associated with extended attributes to the destination file. If
264 \fBcp\fR is unable to copy extended attributes or extended system attributes,
265 then a diagnostic message is written to \fBstderr\fR and (after processing any
266 remaining operands) exits with a \fBnon-zero\fR exit status.
267 .RE
268
269 .sp
270 .LP
271 Specifying more than one of the mutually-exclusive options \fB-H\fR, \fB-L\fR,
272 and \fB-P\fR is not considered an error. The last option specified determines
273 the behavior of the utility.
274 .SS "/usr/bin/cp"
275 .sp
276 .LP
277 If the \fB-p\fR option is specified with either the \fB-@\fR option or the
278 \fB-/\fR option, \fB/usr/bin/cp\fR behaves as follows
279 .RS +4
280 .TP
281 .ie t \(bu
282 .el o
283 When both \fB-p\fR and \fB-@\fR are specified in any order, the copy fails if
284 extended attributes cannot be copied.
285 .RE
286 .RS +4
287 .TP
288 .ie t \(bu
289 .el o
290 When both \fB-p\fR and \fB-/\fR are specified in any order, the copy fails if
291 extended system attributes cannot be copied.
292 .RE
293 .SS "/usr/xpg4/bin/cp"
294 .sp
295 .LP
296 If the \fB-p\fR option is specified with either the \fB-@\fR option or the
297 \fB-/\fR option, /\fBusr/xpg4/bin/cp\fR behaves as follows:
298 .RS +4
299 .TP
300 .ie t \(bu
301 .el o
302 When both \fB-p\fR and \fB-@\fR are specified, the last option specified
303 determines whether the copy fails if extended attributes cannot be preserved.
304 .RE
305 .RS +4
306 .TP
307 .ie t \(bu
308 .el o
309 When both \fB-p\fR and \fB-/\fR are specified, the last option specified
310 determines whether the copy fails if extended system attributes cannot be
311 preserved.
312 .RE
313 .SH OPERANDS
314 .sp
315 .LP
316 The following operands are supported:
317 .sp
318 .ne 2
319 .na
320 \fB\fIsource_file\fR\fR
321 .ad
322 .RS 15n
323 A pathname of a regular file to be copied.
324 .RE
325
326 .sp
327 .ne 2
328 .na
329 \fB\fIsource_dir\fR\fR
330 .ad
331 .RS 15n
332 A pathname of a directory to be copied.
333 .RE
334
335 .sp
336 .ne 2
337 .na
338 \fB\fItarget_file\fR\fR
339 .ad
340 .RS 15n
341 A pathname of an existing or non-existing file, used for the output when a
342 single file is copied.
343 .RE
344
345 .sp
346 .ne 2
347 .na
348 \fB\fItarget\fR\fR
349 .ad
350 .RS 15n
351 A pathname of a directory to contain the copied files.
352 .RE
353
354 .SH USAGE
355 .sp
356 .LP
357 See \fBlargefile\fR(5) for the description of the behavior of \fBcp\fR when
358 encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
359 .SH EXAMPLES
360 .LP
361 \fBExample 1 \fRCopying a File
362 .sp
363 .LP
364 The following example copies a file:
365
366 .sp
367 .in +2
368 .nf
369 example% cp goodies goodies.old
370
371 example% ls goodies*
372 goodies goodies.old
373 .fi
374 .in -2
375 .sp
376
377 .LP
378 \fBExample 2 \fRCopying a List of Files
379 .sp
380 .LP
445
446 .sp
447 .in +2
448 .nf
449 $ ls -/c file1
450 -rw-r--r-- 1 foo staff 0 Oct 29 20:04 file1
451 {AH-----m--}
452
453 $ cp -/ file1 /tmp
454 cp: Failed to copy extended system attributes from file1 to /tmp/file1
455
456
457 $ ls -/c /tmp/file1
458 -rw-r--r-- 1 foo staff 0 Oct 29 20:09 /tmp/file1
459 {}
460 .fi
461 .in -2
462 .sp
463
464 .SH ENVIRONMENT VARIABLES
465 .sp
466 .LP
467 See \fBenviron\fR(5) for descriptions of the following environment variables
468 that affect the execution of \fBcp\fR: \fBLANG\fR, \fBLC_ALL\fR,
469 \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
470 .sp
471 .LP
472 Affirmative responses are processed using the extended regular expression
473 defined for the \fByesexpr\fR keyword in the \fBLC_MESSAGES\fR category of the
474 user's locale. The locale specified in the \fBLC_COLLATE\fR category defines
475 the behavior of ranges, equivalence classes, and multi-character collating
476 elements used in the expression defined for \fByesexpr\fR. The locale specified
477 in \fBLC_CTYPE\fR determines the locale for interpretation of sequences of
478 bytes of text data a characters, the behavior of character classes used in the
479 expression defined for the \fByesexpr\fR. See \fBlocale\fR(5).
480 .SH EXIT STATUS
481 .sp
482 .LP
483 The following exit values are returned:
484 .sp
485 .ne 2
486 .na
487 \fB\fB0\fR\fR
488 .ad
489 .RS 6n
490 All files were copied successfully.
491 .RE
492
493 .sp
494 .ne 2
495 .na
496 \fB\fB>0\fR\fR
497 .ad
498 .RS 6n
499 An error occurred.
500 .RE
501
502 .SH ATTRIBUTES
503 .sp
504 .LP
505 See \fBattributes\fR(5) for descriptions of the following attributes:
506 .SS "/usr/bin/cp"
507 .sp
508
509 .sp
510 .TS
511 box;
512 c | c
513 l | l .
514 ATTRIBUTE TYPE ATTRIBUTE VALUE
515 _
516 CSI Enabled
517 _
518 Interface Stability Committed
519 .TE
520
521 .SS "/usr/xpg4/bin/cp"
522 .sp
523
524 .sp
525 .TS
526 box;
527 c | c
528 l | l .
529 ATTRIBUTE TYPE ATTRIBUTE VALUE
530 _
531 CSI Enabled
532 _
533 Interface Stability Committed
534 .TE
535
536 .SH SEE ALSO
537 .sp
538 .LP
539 \fBchmod\fR(1), \fBchown\fR(1), \fBsetfacl\fR(1), \fButime\fR(2),
540 \fBfgetattr\fR(3C), \fBattributes\fR(5), \fBenviron\fR(5), \fBfsattr\fR(5),
541 \fBlargefile\fR(5), \fBlocale\fR(5), \fBstandards\fR(5)
542 .SH NOTES
543 .sp
544 .LP
545 The permission modes of the source file are preserved in the copy.
546 .sp
547 .LP
548 A \fB--\fR permits the user to mark the end of any command line options
549 explicitly, thus allowing \fBcp\fR to recognize filename arguments that begin
550 with a \fB-\fR.
|
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1989 AT&T
44 .\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved
45 .\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved
46 .\" Copyright 2013 Nexenta Systems, Inc. All rights reserved.
47 .\"
48 .TH CP 1 "May 17, 2020"
49 .SH NAME
50 cp \- copy files
51 .SH SYNOPSIS
52 .nf
53 \fB/usr/bin/cp\fR [\fB-afip@/\fR] \fIsource_file\fR \fItarget_file\fR
54 .fi
55
56 .LP
57 .nf
58 \fB/usr/bin/cp\fR [\fB-afip@/\fR] \fIsource_file\fR... \fItarget\fR
59 .fi
60
61 .LP
62 .nf
63 \fB/usr/bin/cp\fR [\fB-r\fR | \fB-R\fR [\fB-H\fR | \fB-L\fR | \fB-P\fR]] [\fB-afip@/\fR] \fIsource_dir\fR... \fItarget\fR
64 .fi
65
66 .LP
67 .nf
68 \fB/usr/bin/cp\fR [\fB-R\fR | \fB-R\fR [\fB-H\fR | \fB-L\fR | \fB-P\fR]] [\fB-afip@/\fR] \fIsource_dir\fR... \fItarget\fR
69 .fi
70
71 .LP
72 .nf
73 \fB/usr/xpg4/bin/cp\fR [\fB-afip@/\fR] \fIsource_file\fR \fItarget_file\fR
74 .fi
75
76 .LP
77 .nf
78 \fB/usr/xpg4/bin/cp\fR [\fB-afip@/\fR] \fIsource_file\fR... \fItarget\fR
79 .fi
80
81 .LP
82 .nf
83 \fB/usr/xpg4/bin/cp\fR [\fB-r\fR | \fB-R\fR [\fB-H\fR | \fB-L\fR | \fB-P\fR]] [\fB-afip@/\fR] \fIsource_dir\fR... \fItarget\fR
84 .fi
85
86 .LP
87 .nf
88 \fB/usr/xpg4/bin/cp\fR [\fB-R\fR | \fB-R\fR [\fB-H\fR | \fB-L\fR | \fB-P\fR]] [\fB-afip@/\fR] \fIsource_dir\fR... \fItarget\fR
89 .fi
90
91 .SH DESCRIPTION
92 In the first synopsis form, neither \fIsource_file\fR nor \fItarget_file\fR are
93 directory files, nor can they have the same name. The \fBcp\fR utility copies
94 the contents of \fIsource_file\fR to the destination path named by
95 \fItarget_file\fR. If \fItarget_file\fR exists, \fBcp\fR overwrites its
96 contents, but the mode (and \fBACL\fR if applicable), owner, and group
97 associated with it are not changed. The last modification time of
98 \fItarget_file\fR and the last access time of \fIsource_file\fR are set to the
99 time the copy was made. If \fItarget_file\fR does not exist, \fBcp\fR creates a
100 new file named \fItarget_file\fR that has the same mode as \fIsource_file\fR
101 except that the sticky bit is not set unless the user is super-user. In this
102 case, the owner and group of \fItarget_file\fR are those of the user, unless
103 the setgid bit is set on the directory containing the newly created file. If
104 the directory's setgid bit is set, the newly created file has the group of the
105 containing directory rather than of the creating user. If \fItarget_file\fR is
106 a link to another file, \fBcp\fR overwrites the link destination with the
107 contents of \fIsource_file\fR; the link(s) from \fItarget_file\fR remains.
108 .sp
109 .LP
110 In the second synopsis form, one or more \fIsource_file\fRs are copied to the
111 directory specified by \fItarget\fR. It is an error if any \fIsource_file\fR is
112 a file of type directory, if \fItarget\fR either does not exist or is not a
113 directory.
114 .sp
115 .LP
116 In the third or fourth synopsis forms, one or more directories specified by
117 \fIsource_dir\fR are copied to the directory specified by \fItarget\fR. Either
118 the \fB-r\fR or \fB-R\fR must be specified. For each \fIsource_dir\fR, \fBcp\fR
119 copies all files and subdirectories.
120 .SH OPTIONS
121 The following options are supported for both \fB/usr/bin/cp\fR and
122 \fB/usr/xpg4/bin/cp\fR:
123 .sp
124 .ne 2
125 .na
126 \fB\fB-a\fR\fR
127 .ad
128 .RS 6n
129 Archive mode. Same as -RpP.
130 .RE
131
132 .sp
133 .ne 2
134 .na
135 \fB\fB-f\fR\fR
136 .ad
137 .RS 6n
138 Unlink. If a file descriptor for a destination file cannot be obtained, this
139 option attempts to unlink the destination file and proceed.
140 .RE
250 .ne 2
251 .na
252 \fB\fB-/\fR\fR
253 .ad
254 .RS 6n
255 Preserves extended attributes and extended system attributes. Along with the
256 file's data, the \fBcp\fR utility attempts to copy extended attributes and
257 extended system attributes from each source file, and extended system
258 attributes associated with extended attributes to the destination file. If
259 \fBcp\fR is unable to copy extended attributes or extended system attributes,
260 then a diagnostic message is written to \fBstderr\fR and (after processing any
261 remaining operands) exits with a \fBnon-zero\fR exit status.
262 .RE
263
264 .sp
265 .LP
266 Specifying more than one of the mutually-exclusive options \fB-H\fR, \fB-L\fR,
267 and \fB-P\fR is not considered an error. The last option specified determines
268 the behavior of the utility.
269 .SS "/usr/bin/cp"
270 If the \fB-p\fR option is specified with either the \fB-@\fR option or the
271 \fB-/\fR option, \fB/usr/bin/cp\fR behaves as follows
272 .RS +4
273 .TP
274 .ie t \(bu
275 .el o
276 When both \fB-p\fR and \fB-@\fR are specified in any order, the copy fails if
277 extended attributes cannot be copied.
278 .RE
279 .RS +4
280 .TP
281 .ie t \(bu
282 .el o
283 When both \fB-p\fR and \fB-/\fR are specified in any order, the copy fails if
284 extended system attributes cannot be copied.
285 .RE
286 .SS "/usr/xpg4/bin/cp"
287 If the \fB-p\fR option is specified with either the \fB-@\fR option or the
288 \fB-/\fR option, \fB/usr/xpg4/bin/cp\fR behaves as follows:
289 .RS +4
290 .TP
291 .ie t \(bu
292 .el o
293 When both \fB-p\fR and \fB-@\fR are specified, the last option specified
294 determines whether the copy fails if extended attributes cannot be preserved.
295 .RE
296 .RS +4
297 .TP
298 .ie t \(bu
299 .el o
300 When both \fB-p\fR and \fB-/\fR are specified, the last option specified
301 determines whether the copy fails if extended system attributes cannot be
302 preserved.
303 .RE
304 .SH OPERANDS
305 The following operands are supported:
306 .sp
307 .ne 2
308 .na
309 \fB\fIsource_file\fR\fR
310 .ad
311 .RS 15n
312 A pathname of a regular file to be copied.
313 .RE
314
315 .sp
316 .ne 2
317 .na
318 \fB\fIsource_dir\fR\fR
319 .ad
320 .RS 15n
321 A pathname of a directory to be copied.
322 .RE
323
324 .sp
325 .ne 2
326 .na
327 \fB\fItarget_file\fR\fR
328 .ad
329 .RS 15n
330 A pathname of an existing or non-existing file, used for the output when a
331 single file is copied.
332 .RE
333
334 .sp
335 .ne 2
336 .na
337 \fB\fItarget\fR\fR
338 .ad
339 .RS 15n
340 A pathname of a directory to contain the copied files.
341 .RE
342
343 .SH USAGE
344 See \fBlargefile\fR(5) for the description of the behavior of \fBcp\fR when
345 encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
346 .SH EXAMPLES
347 \fBExample 1 \fRCopying a File
348 .sp
349 .LP
350 The following example copies a file:
351
352 .sp
353 .in +2
354 .nf
355 example% cp goodies goodies.old
356
357 example% ls goodies*
358 goodies goodies.old
359 .fi
360 .in -2
361 .sp
362
363 .LP
364 \fBExample 2 \fRCopying a List of Files
365 .sp
366 .LP
431
432 .sp
433 .in +2
434 .nf
435 $ ls -/c file1
436 -rw-r--r-- 1 foo staff 0 Oct 29 20:04 file1
437 {AH-----m--}
438
439 $ cp -/ file1 /tmp
440 cp: Failed to copy extended system attributes from file1 to /tmp/file1
441
442
443 $ ls -/c /tmp/file1
444 -rw-r--r-- 1 foo staff 0 Oct 29 20:09 /tmp/file1
445 {}
446 .fi
447 .in -2
448 .sp
449
450 .SH ENVIRONMENT VARIABLES
451 See \fBenviron\fR(5) for descriptions of the following environment variables
452 that affect the execution of \fBcp\fR: \fBLANG\fR, \fBLC_ALL\fR,
453 \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
454 .sp
455 .LP
456 Affirmative responses are processed using the extended regular expression
457 defined for the \fByesexpr\fR keyword in the \fBLC_MESSAGES\fR category of the
458 user's locale. The locale specified in the \fBLC_COLLATE\fR category defines
459 the behavior of ranges, equivalence classes, and multi-character collating
460 elements used in the expression defined for \fByesexpr\fR. The locale specified
461 in \fBLC_CTYPE\fR determines the locale for interpretation of sequences of
462 bytes of text data a characters, the behavior of character classes used in the
463 expression defined for the \fByesexpr\fR. See \fBlocale\fR(5).
464 .SH EXIT STATUS
465 The following exit values are returned:
466 .sp
467 .ne 2
468 .na
469 \fB\fB0\fR\fR
470 .ad
471 .RS 6n
472 All files were copied successfully.
473 .RE
474
475 .sp
476 .ne 2
477 .na
478 \fB\fB>0\fR\fR
479 .ad
480 .RS 6n
481 An error occurred.
482 .RE
483
484 .SH ATTRIBUTES
485 See \fBattributes\fR(5) for descriptions of the following attributes:
486 .SS "/usr/bin/cp"
487 .TS
488 box;
489 c | c
490 l | l .
491 ATTRIBUTE TYPE ATTRIBUTE VALUE
492 _
493 CSI Enabled
494 _
495 Interface Stability Committed
496 .TE
497
498 .SS "/usr/xpg4/bin/cp"
499 .TS
500 box;
501 c | c
502 l | l .
503 ATTRIBUTE TYPE ATTRIBUTE VALUE
504 _
505 CSI Enabled
506 _
507 Interface Stability Committed
508 .TE
509
510 .SH SEE ALSO
511 \fBchmod\fR(1), \fBchown\fR(1), \fBsetfacl\fR(1), \fButime\fR(2),
512 \fBfgetattr\fR(3C), \fBattributes\fR(5), \fBenviron\fR(5), \fBfsattr\fR(5),
513 \fBlargefile\fR(5), \fBlocale\fR(5), \fBstandards\fR(5)
514 .SH NOTES
515 The permission modes of the source file are preserved in the copy.
516 .sp
517 .LP
518 A \fB--\fR permits the user to mark the end of any command line options
519 explicitly, thus allowing \fBcp\fR to recognize filename arguments that begin
520 with a \fB-\fR.
|