logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

cp.1p (25004B)


  1. '\" et
  2. .TH CP "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. cp
  12. \(em copy files
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. cp \fB[\fR-Pfip\fB] \fIsource_file target_file\fR
  17. .P
  18. cp \fB[\fR-Pfip\fB] \fIsource_file\fR... \fItarget\fR
  19. .P
  20. cp -R \fB[\fR-H|-L|-P\fB] [\fR-fip\fB] \fIsource_file\fR... \fItarget\fR
  21. .fi
  22. .SH DESCRIPTION
  23. The first synopsis form is denoted by two operands, neither of which
  24. are existing files of type directory. The
  25. .IR cp
  26. utility shall copy the contents of
  27. .IR source_file
  28. (or, if
  29. .IR source_file
  30. is a file of type symbolic link, the contents of the file referenced by
  31. .IR source_file )
  32. to the destination path named by
  33. .IR target_file.
  34. .P
  35. The second synopsis form is denoted by two or more operands where the
  36. .BR \-R
  37. option is not specified and the first synopsis form is not
  38. applicable. It shall be an error if any
  39. .IR source_file
  40. is a file of type directory, if
  41. .IR target
  42. does not exist, or if
  43. .IR target
  44. does not name a directory. The
  45. .IR cp
  46. utility shall copy the contents of each
  47. .IR source_file
  48. (or, if
  49. .IR source_file
  50. is a file of type symbolic link, the contents of the file referenced by
  51. .IR source_file )
  52. to the destination path named by the concatenation of
  53. .IR target ,
  54. a single
  55. <slash>
  56. character if
  57. .IR target
  58. did not end in a
  59. <slash>,
  60. and the last component of
  61. .IR source_file .
  62. .P
  63. The third synopsis form is denoted by two or more operands where the
  64. .BR \-R
  65. option is specified. The
  66. .IR cp
  67. utility shall copy each file in the file hierarchy rooted in each
  68. .IR source_file
  69. to a destination path named as follows:
  70. .IP " *" 4
  71. If
  72. .IR target
  73. exists and names an existing directory, the name of the corresponding
  74. destination path for each file in the file hierarchy shall be the
  75. concatenation of
  76. .IR target ,
  77. a single
  78. <slash>
  79. character if
  80. .IR target
  81. did not end in a
  82. <slash>,
  83. and the pathname of the file relative to the directory containing
  84. .IR source_file .
  85. .IP " *" 4
  86. If
  87. .IR target
  88. does not exist and two operands are specified, the name of the
  89. corresponding destination path for
  90. .IR source_file
  91. shall be
  92. .IR target ;
  93. the name of the corresponding destination path for all other files in
  94. the file hierarchy shall be the concatenation of
  95. .IR target ,
  96. a
  97. <slash>
  98. character, and the pathname of the file relative to
  99. .IR source_file .
  100. .P
  101. It shall be an error if
  102. .IR target
  103. does not exist and more than two operands are specified, or if
  104. .IR target
  105. exists and does not name a directory.
  106. .P
  107. In the following description, the term
  108. .IR dest_file
  109. refers to the file named by the destination path. The term
  110. .IR source_file
  111. refers to the file that is being copied, whether specified as an
  112. operand or a file in a file hierarchy rooted in a
  113. .IR source_file
  114. operand. If
  115. .IR source_file
  116. is a file of type symbolic link:
  117. .IP " *" 4
  118. If the
  119. .BR \-R
  120. option was not specified,
  121. .IR cp
  122. shall take actions based on the type and contents of the file referenced
  123. by the symbolic link, and not by the symbolic link itself, unless the
  124. .BR \-P
  125. option was specified.
  126. .IP " *" 4
  127. If the
  128. .BR \-R
  129. option was specified:
  130. .RS 4
  131. .IP -- 4
  132. If none of the options
  133. .BR \-H ,
  134. .BR \-L ,
  135. nor
  136. .BR \-P
  137. were specified, it is unspecified which of
  138. .BR \-H ,
  139. .BR \-L ,
  140. or
  141. .BR \-P
  142. will be used as a default.
  143. .IP -- 4
  144. If the
  145. .BR \-H
  146. option was specified,
  147. .IR cp
  148. shall take actions based on the type and contents of the
  149. file referenced by any symbolic link specified as a
  150. .IR source_file
  151. operand.
  152. .IP -- 4
  153. If the
  154. .BR \-L
  155. option was specified,
  156. .IR cp
  157. shall take actions based on the type and contents of the
  158. file referenced by any symbolic link specified as a
  159. .IR source_file
  160. operand or any symbolic links encountered during traversal of a
  161. file hierarchy.
  162. .IP -- 4
  163. If the
  164. .BR \-P
  165. option was specified,
  166. .IR cp
  167. shall copy any symbolic link specified as a
  168. .IR source_file
  169. operand and any symbolic links encountered during traversal of a
  170. file hierarchy, and shall not follow any symbolic links.
  171. .RE
  172. .P
  173. For each
  174. .IR source_file ,
  175. the following steps shall be taken:
  176. .IP " 1." 4
  177. If
  178. .IR source_file
  179. references the same file as
  180. .IR dest_file ,
  181. .IR cp
  182. may write a diagnostic message to standard error; it shall do nothing
  183. more with
  184. .IR source_file
  185. and shall go on to any remaining files.
  186. .IP " 2." 4
  187. If
  188. .IR source_file
  189. is of type directory, the following steps shall be taken:
  190. .RS 4
  191. .IP " a." 4
  192. If the
  193. .BR \-R
  194. option was not specified,
  195. .IR cp
  196. shall write a diagnostic message to standard error, do nothing more
  197. with
  198. .IR source_file ,
  199. and go on to any remaining files.
  200. .IP " b." 4
  201. If
  202. .IR source_file
  203. was not specified as an operand and
  204. .IR source_file
  205. is dot or dot-dot,
  206. .IR cp
  207. shall do nothing more with
  208. .IR source_file
  209. and go on to any remaining files.
  210. .IP " c." 4
  211. If
  212. .IR dest_file
  213. exists and it is a file type not specified by the System Interfaces volume of POSIX.1\(hy2017, the behavior
  214. is implementation-defined.
  215. .IP " d." 4
  216. If
  217. .IR dest_file
  218. exists and it is not of type directory,
  219. .IR cp
  220. shall write a diagnostic message to standard error, do nothing more
  221. with
  222. .IR source_file
  223. or any files below
  224. .IR source_file
  225. in the file hierarchy, and go on to any remaining files.
  226. .IP " e." 4
  227. If the directory
  228. .IR dest_file
  229. does not exist, it shall be created with file permission bits set to
  230. the same value as those of
  231. .IR source_file ,
  232. modified by the file creation mask of the user if the
  233. .BR \-p
  234. option was not specified, and then bitwise-inclusively OR'ed with
  235. S_IRWXU. If
  236. .IR dest_file
  237. cannot be created,
  238. .IR cp
  239. shall write a diagnostic message to standard error, do nothing more
  240. with
  241. .IR source_file ,
  242. and go on to any remaining files. It is unspecified if
  243. .IR cp
  244. attempts to copy files in the file hierarchy rooted in
  245. .IR source_file .
  246. .IP " f." 4
  247. The files in the directory
  248. .IR source_file
  249. shall be copied to the directory
  250. .IR dest_file ,
  251. taking the four steps (1 to 4) listed here with the files as
  252. .IR source_file s.
  253. .IP " g." 4
  254. If
  255. .IR dest_file
  256. was created, its file permission bits shall be changed (if necessary)
  257. to be the same as those of
  258. .IR source_file ,
  259. modified by the file creation mask of the user if the
  260. .BR \-p
  261. option was not specified.
  262. .IP " h." 4
  263. The
  264. .IR cp
  265. utility shall do nothing more with
  266. .IR source_file
  267. and go on to any remaining files.
  268. .RE
  269. .IP " 3." 4
  270. If
  271. .IR source_file
  272. is of type regular file, the following steps shall be taken:
  273. .RS 4
  274. .IP " a." 4
  275. The behavior is unspecified if
  276. .IR dest_file
  277. exists and was written by a previous step. Otherwise, if
  278. .IR dest_file
  279. exists, the following steps shall be taken:
  280. .RS 4
  281. .IP " i." 5
  282. If the
  283. .BR \-i
  284. option is in effect, the
  285. .IR cp
  286. utility shall write a prompt to the standard error and read a line from
  287. the standard input. If the response is not affirmative,
  288. .IR cp
  289. shall do nothing more with
  290. .IR source_file
  291. and go on to any remaining files.
  292. .IP ii. 5
  293. A file descriptor for
  294. .IR dest_file
  295. shall be obtained by performing actions equivalent to the
  296. \fIopen\fR()
  297. function defined in the System Interfaces volume of POSIX.1\(hy2017 called using
  298. .IR dest_file
  299. as the
  300. .IR path
  301. argument, and the bitwise-inclusive OR of O_WRONLY and O_TRUNC as the
  302. .IR oflag
  303. argument.
  304. .IP iii. 5
  305. If the attempt to obtain a file descriptor fails and the
  306. .BR \-f
  307. option is in effect,
  308. .IR cp
  309. shall attempt to remove the file by performing actions equivalent to
  310. the
  311. \fIunlink\fR()
  312. function defined in the System Interfaces volume of POSIX.1\(hy2017 called using
  313. .IR dest_file
  314. as the
  315. .IR path
  316. argument. If this attempt succeeds,
  317. .IR cp
  318. shall continue with step 3b.
  319. .RE
  320. .IP " b." 4
  321. If
  322. .IR dest_file
  323. does not exist, a file descriptor shall be obtained by performing
  324. actions equivalent to the
  325. \fIopen\fR()
  326. function defined in the System Interfaces volume of POSIX.1\(hy2017 called using
  327. .IR dest_file
  328. as the
  329. .IR path
  330. argument, and the bitwise-inclusive OR of O_WRONLY and O_CREAT as the
  331. .IR oflag
  332. argument. The file permission bits of
  333. .IR source_file
  334. shall be the
  335. .IR mode
  336. argument.
  337. .IP " c." 4
  338. If the attempt to obtain a file descriptor fails,
  339. .IR cp
  340. shall write a diagnostic message to standard error, do nothing more with
  341. .IR source_file ,
  342. and go on to any remaining files.
  343. .IP " d." 4
  344. The contents of
  345. .IR source_file
  346. shall be written to the file descriptor. Any write errors shall cause
  347. .IR cp
  348. to write a diagnostic message to standard error and continue to step
  349. 3e.
  350. .IP " e." 4
  351. The file descriptor shall be closed.
  352. .IP " f." 4
  353. The
  354. .IR cp
  355. utility shall do nothing more with
  356. .IR source_file .
  357. If a write error occurred in step 3d, it is unspecified if
  358. .IR cp
  359. continues with any remaining files. If no write error occurred in step
  360. 3d,
  361. .IR cp
  362. shall go on to any remaining files.
  363. .RE
  364. .IP " 4." 4
  365. Otherwise, the
  366. .BR \-R
  367. option was specified, and the following steps shall be taken:
  368. .RS 4
  369. .IP " a." 4
  370. The
  371. .IR dest_file
  372. shall be created with the same file type as
  373. .IR source_file .
  374. .IP " b." 4
  375. If
  376. .IR source_file
  377. is a file of type FIFO, the file permission bits shall be the same as
  378. those of
  379. .IR source_file,
  380. modified by the file creation mask of the user if the
  381. .BR \-p
  382. option was not specified. Otherwise, the permissions, owner ID, and
  383. group ID of
  384. .IR dest_file
  385. are implementation-defined.
  386. .RS 4
  387. .P
  388. If this creation fails for any reason,
  389. .IR cp
  390. shall write a diagnostic message to standard error, do nothing more
  391. with
  392. .IR source_file ,
  393. and go on to any remaining files.
  394. .RE
  395. .IP " c." 4
  396. If
  397. .IR source_file
  398. is a file of type symbolic link, and the options require the symbolic
  399. link itself to be acted upon, the pathname contained in
  400. .IR dest_file
  401. shall be the same as the pathname contained in
  402. .IR source_file .
  403. .RS 4
  404. .P
  405. If this fails for any reason,
  406. .IR cp
  407. shall write a diagnostic message to standard error, do nothing more
  408. with
  409. .IR source_file ,
  410. and go on to any remaining files.
  411. .RE
  412. .RE
  413. .P
  414. If the implementation provides additional or alternate access control
  415. mechanisms (see the Base Definitions volume of POSIX.1\(hy2017,
  416. .IR "Section 4.5" ", " "File Access Permissions"),
  417. their effect on copies of files is implementation-defined.
  418. .SH OPTIONS
  419. The
  420. .IR cp
  421. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  422. .IR "Section 12.2" ", " "Utility Syntax Guidelines".
  423. .P
  424. The following options shall be supported:
  425. .IP "\fB\-f\fP" 10
  426. If a file descriptor for a destination file cannot be obtained, as
  427. described in step 3.a.ii., attempt to unlink the destination file and
  428. proceed.
  429. .IP "\fB\-H\fP" 10
  430. Take actions based on the type and contents of the file referenced by
  431. any symbolic link specified as a
  432. .IR source_file
  433. operand.
  434. .IP "\fB\-i\fP" 10
  435. Write a prompt to standard error before copying to any existing
  436. non-directory destination file. If the response from the standard input
  437. is affirmative, the copy shall be attempted; otherwise, it shall not.
  438. .IP "\fB\-L\fP" 10
  439. Take actions based on the type and contents of the file referenced by
  440. any symbolic link specified as a
  441. .IR source_file
  442. operand or any symbolic links encountered during traversal of a
  443. file hierarchy.
  444. .IP "\fB\-P\fP" 10
  445. Take actions on any symbolic link specified as a
  446. .IR source_file
  447. operand or any symbolic link encountered during traversal of a
  448. file hierarchy.
  449. .IP "\fB\-p\fP" 10
  450. Duplicate the following characteristics of each source file in the
  451. corresponding destination file:
  452. .RS 10
  453. .IP " 1." 4
  454. The time of last data modification and time of last access. If this
  455. duplication fails for any reason,
  456. .IR cp
  457. shall write a diagnostic message to standard error.
  458. .IP " 2." 4
  459. The user ID and group ID. If this duplication fails for any reason, it
  460. is unspecified whether
  461. .IR cp
  462. writes a diagnostic message to standard error.
  463. .IP " 3." 4
  464. The file permission bits and the S_ISUID and S_ISGID bits. Other,
  465. implementation-defined, bits may be duplicated as well. If this
  466. duplication fails for any reason,
  467. .IR cp
  468. shall write a diagnostic message to standard error.
  469. .P
  470. If the user ID or the group ID cannot be duplicated, the file
  471. permission bits S_ISUID and S_ISGID shall be cleared. If these bits are
  472. present in the source file but are not duplicated in the destination
  473. file, it is unspecified whether
  474. .IR cp
  475. writes a diagnostic message to standard error.
  476. .P
  477. The order in which the preceding characteristics are duplicated is
  478. unspecified. The
  479. .IR dest_file
  480. shall not be deleted if these characteristics cannot be preserved.
  481. .RE
  482. .IP "\fB\-R\fR" 10
  483. Copy file hierarchies.
  484. .P
  485. Specifying more than one of the mutually-exclusive options
  486. .BR \-H ,
  487. .BR \-L ,
  488. and
  489. .BR \-P
  490. shall not be considered an error. The last option specified shall
  491. determine the behavior of the utility.
  492. .SH OPERANDS
  493. The following operands shall be supported:
  494. .IP "\fIsource_file\fR" 10
  495. A pathname of a file to be copied. If a
  496. .IR source_file
  497. operand is
  498. .BR '\-' ,
  499. it shall refer to a file named
  500. .BR \- ;
  501. implementations shall not treat it as meaning standard input.
  502. .IP "\fItarget_file\fR" 10
  503. A pathname of an existing or nonexistent file, used for the output when
  504. a single file is copied. If a
  505. .IR target_file
  506. operand is
  507. .BR '\-' ,
  508. it shall refer to a file named
  509. .BR \- ;
  510. implementations shall not treat it as meaning standard output.
  511. .IP "\fItarget\fR" 10
  512. A pathname of a directory to contain the copied files.
  513. .SH STDIN
  514. The standard input shall be used to read an input line in response to
  515. each prompt specified in the STDERR section. Otherwise, the standard
  516. input shall not be used.
  517. .SH "INPUT FILES"
  518. The input files specified as operands may be of any file type.
  519. .SH "ENVIRONMENT VARIABLES"
  520. The following environment variables shall affect the execution of
  521. .IR cp :
  522. .IP "\fILANG\fP" 10
  523. Provide a default value for the internationalization variables that are
  524. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  525. .IR "Section 8.2" ", " "Internationalization Variables"
  526. for the precedence of internationalization variables used to determine
  527. the values of locale categories.)
  528. .IP "\fILC_ALL\fP" 10
  529. If set to a non-empty string value, override the values of all the
  530. other internationalization variables.
  531. .IP "\fILC_COLLATE\fP" 10
  532. .br
  533. Determine the locale for the behavior of ranges, equivalence classes,
  534. and multi-character collating elements used in the extended regular
  535. expression defined for the
  536. .BR yesexpr
  537. locale keyword in the
  538. .IR LC_MESSAGES
  539. category.
  540. .IP "\fILC_CTYPE\fP" 10
  541. Determine the locale for the interpretation of sequences of bytes of
  542. text data as characters (for example, single-byte as opposed to
  543. multi-byte characters in arguments and input files) and the behavior of
  544. character classes used in the extended regular expression defined for
  545. the
  546. .BR yesexpr
  547. locale keyword in the
  548. .IR LC_MESSAGES
  549. category.
  550. .IP "\fILC_MESSAGES\fP" 10
  551. .br
  552. Determine the locale used to process affirmative responses, and the
  553. locale used to affect the format and contents of diagnostic messages
  554. and prompts written to standard error.
  555. .IP "\fINLSPATH\fP" 10
  556. Determine the location of message catalogs for the processing of
  557. .IR LC_MESSAGES .
  558. .SH "ASYNCHRONOUS EVENTS"
  559. Default.
  560. .SH STDOUT
  561. Not used.
  562. .SH STDERR
  563. A prompt shall be written to standard error under the conditions
  564. specified in the DESCRIPTION section. The prompt shall contain the
  565. destination pathname, but its format is otherwise unspecified.
  566. Otherwise, the standard error shall be used only for diagnostic
  567. messages.
  568. .SH "OUTPUT FILES"
  569. The output files may be of any type.
  570. .SH "EXTENDED DESCRIPTION"
  571. None.
  572. .SH "EXIT STATUS"
  573. The following exit values shall be returned:
  574. .IP "\00" 6
  575. All files were copied successfully.
  576. .IP >0 6
  577. An error occurred.
  578. .SH "CONSEQUENCES OF ERRORS"
  579. If
  580. .IR cp
  581. is prematurely terminated by a signal or error, files or file
  582. hierarchies may be only partially copied and files and directories may
  583. have incorrect permissions or access and modification times.
  584. .LP
  585. .IR "The following sections are informative."
  586. .SH "APPLICATION USAGE"
  587. The set-user-ID and set-group-ID bits are explicitly cleared when files
  588. are created. This is to prevent users from creating programs that are
  589. set-user-ID or set-group-ID to them when copying files or to make
  590. set-user-ID or set-group-ID files accessible to new groups of users.
  591. For example, if a file is set-user-ID and the copy has a different
  592. group ID than the source, a new group of users has execute permission
  593. to a set-user-ID program than did previously. In particular, this is a
  594. problem for superusers copying users' trees.
  595. .SH EXAMPLES
  596. None.
  597. .SH RATIONALE
  598. The
  599. .BR \-i
  600. option exists on BSD systems, giving applications and users a way to
  601. avoid accidentally removing files when copying. Although the 4.3 BSD
  602. version does not prompt if the standard input is not a terminal, the
  603. standard developers decided that use of
  604. .BR \-i
  605. is a request for interaction, so when the destination path exists, the
  606. utility takes instructions from whatever responds on standard input.
  607. .P
  608. The exact format of the interactive prompts is unspecified. Only the
  609. general nature of the contents of prompts are specified because
  610. implementations may desire more descriptive prompts than those used on
  611. historical implementations. Therefore, an application using the
  612. .BR \-i
  613. option relies on the system to provide the most suitable dialog
  614. directly with the user, based on the behavior specified.
  615. .P
  616. The
  617. .BR \-p
  618. option is historical practice on BSD systems, duplicating the time of
  619. last data modification and time of last access. This volume of POSIX.1\(hy2017 extends it to
  620. preserve the user and group IDs, as well as the file permissions. This
  621. requirement has obvious problems in that the directories are almost
  622. certainly modified after being copied. This volume of POSIX.1\(hy2017 requires that the
  623. modification times be preserved. The statement that the order in which
  624. the characteristics are duplicated is unspecified is to permit
  625. implementations to provide the maximum amount of security for the user.
  626. Implementations should take into account the obvious security issues
  627. involved in setting the owner, group, and mode in the wrong order or
  628. creating files with an owner, group, or mode different from the final
  629. value.
  630. .P
  631. It is unspecified whether
  632. .IR cp
  633. writes diagnostic messages when the user and group IDs cannot be set
  634. due to the widespread practice of users using
  635. .BR \-p
  636. to duplicate some portion of the file characteristics, indifferent to
  637. the duplication of others. Historic implementations only write
  638. diagnostic messages on errors other than
  639. .BR [EPERM] .
  640. .P
  641. Earlier versions of this standard included support for the
  642. .BR \-r
  643. option to copy file hierarchies. The
  644. .BR \-r
  645. option is historical practice on BSD and BSD-derived systems. This
  646. option is no longer specified by POSIX.1\(hy2008 but may be present
  647. in some implementations. The
  648. .BR \-R
  649. option was added as a close synonym to the
  650. .BR \-r
  651. option, selected for consistency with all other options in this volume of POSIX.1\(hy2017 that
  652. do recursive directory descent.
  653. .P
  654. The difference between
  655. .BR \-R
  656. and the removed
  657. .BR \-r
  658. option is in the treatment by
  659. .IR cp
  660. of file types other than regular and directory. It was
  661. implementation-defined how the
  662. .BR \-
  663. option treated special files to allow both historical implementations
  664. and those that chose to support
  665. .BR \-r
  666. with the same abilities as
  667. .BR \-R
  668. defined by this volume of POSIX.1\(hy2017. The original
  669. .BR \-r
  670. flag, for historic reasons, did not handle special files any differently
  671. from regular files, but always read the file and copied its contents. This
  672. had obvious problems in the presence of special file types; for example,
  673. character devices, FIFOs, and sockets.
  674. .P
  675. When a failure occurs during the copying of a file hierarchy,
  676. .IR cp
  677. is required to attempt to copy files that are on the same level in the
  678. hierarchy or above the file where the failure occurred. It is
  679. unspecified if
  680. .IR cp
  681. shall attempt to copy files below the file where the failure occurred
  682. (which cannot succeed in any case).
  683. .P
  684. Permissions, owners, and groups of created special file types have been
  685. deliberately left as implementation-defined. This is to allow systems
  686. to satisfy special requirements (for example, allowing users to create
  687. character special devices, but requiring them to be owned by a certain
  688. group). In general, it is strongly suggested that the permissions,
  689. owner, and group be the same as if the user had run the historical
  690. .IR mknod ,
  691. .IR ln ,
  692. or other utility to create the file. It is also probable that
  693. additional privileges are required to create block, character, or
  694. other implementation-defined special file types.
  695. .P
  696. Additionally, the
  697. .BR \-p
  698. option explicitly requires that all set-user-ID
  699. and set-group-ID permissions be
  700. discarded if any of the owner or group IDs cannot be set. This is to
  701. keep users from unintentionally giving away special privilege when
  702. copying programs.
  703. .P
  704. When creating regular files, historical versions of
  705. .IR cp
  706. use the mode of the source file as modified by the file mode creation
  707. mask. Other choices would have been to use the mode of the source file
  708. unmodified by the creation mask or to use the same mode as would be
  709. given to a new file created by the user (plus the execution bits of the
  710. source file) and then modify it by the file mode creation mask. In the
  711. absence of any strong reason to change historic practice, it was in
  712. large part retained.
  713. .P
  714. When creating directories, historical versions of
  715. .IR cp
  716. use the mode of the source directory, plus read, write, and search bits
  717. for the owner, as modified by the file mode creation mask. This is done
  718. so that
  719. .IR cp
  720. can copy trees where the user has read permission, but the owner does
  721. not. A side-effect is that if the file creation mask denies the owner
  722. permissions,
  723. .IR cp
  724. fails. Also, once the copy is done, historical versions of
  725. .IR cp
  726. set the permissions on the created directory to be the same as the
  727. source directory, unmodified by the file creation mask.
  728. .P
  729. This behavior has been modified so that
  730. .IR cp
  731. is always able to create the contents of the directory, regardless of
  732. the file creation mask. After the copy is done, the permissions are set
  733. to be the same as the source directory, as modified by the file
  734. creation mask. This latter change from historical behavior is to
  735. prevent users from accidentally creating directories with permissions
  736. beyond those they would normally set and for consistency with the
  737. behavior of
  738. .IR cp
  739. in creating files.
  740. .P
  741. It is not a requirement that
  742. .IR cp
  743. detect attempts to copy a file to itself; however, implementations are
  744. strongly encouraged to do so. Historical implementations have detected
  745. the attempt in most cases.
  746. .P
  747. There are two methods of copying subtrees in this volume of POSIX.1\(hy2017. The other method is
  748. described as part of the
  749. .IR pax
  750. utility (see
  751. .IR "\fIpax\fR\^").
  752. Both methods are historical practice. The
  753. .IR cp
  754. utility provides a simpler, more intuitive interface, while
  755. .IR pax
  756. offers a finer granularity of control. Each provides additional
  757. functionality to the other; in particular,
  758. .IR pax
  759. maintains the hard-link structure of the hierarchy, while
  760. .IR cp
  761. does not. It is the intention of the standard developers that the
  762. results be similar (using appropriate option combinations in both
  763. utilities). The results are not required to be identical; there seemed
  764. insufficient gain to applications to balance the difficulty of
  765. implementations having to guarantee that the results would be exactly
  766. identical.
  767. .P
  768. The wording allowing
  769. .IR cp
  770. to copy a directory to implementation-defined file types not
  771. specified by the System Interfaces volume of POSIX.1\(hy2017 is provided so that implementations supporting
  772. symbolic links are not required to prohibit copying directories to
  773. symbolic links. Other extensions to the System Interfaces volume of POSIX.1\(hy2017 file types may need to
  774. use this loophole as well.
  775. .SH "FUTURE DIRECTIONS"
  776. None.
  777. .SH "SEE ALSO"
  778. .IR "\fImv\fR\^",
  779. .IR "\fIfind\fR\^",
  780. .IR "\fIln\fR\^",
  781. .IR "\fIpax\fR\^"
  782. .P
  783. The Base Definitions volume of POSIX.1\(hy2017,
  784. .IR "Section 4.5" ", " "File Access Permissions",
  785. .IR "Chapter 8" ", " "Environment Variables",
  786. .IR "Section 12.2" ", " "Utility Syntax Guidelines"
  787. .P
  788. The System Interfaces volume of POSIX.1\(hy2017,
  789. .IR "\fIopen\fR\^(\|)",
  790. .IR "\fIunlink\fR\^(\|)"
  791. .\"
  792. .SH COPYRIGHT
  793. Portions of this text are reprinted and reproduced in electronic form
  794. from IEEE Std 1003.1-2017, Standard for Information Technology
  795. -- Portable Operating System Interface (POSIX), The Open Group Base
  796. Specifications Issue 7, 2018 Edition,
  797. Copyright (C) 2018 by the Institute of
  798. Electrical and Electronics Engineers, Inc and The Open Group.
  799. In the event of any discrepancy between this version and the original IEEE and
  800. The Open Group Standard, the original IEEE and The Open Group Standard
  801. is the referee document. The original Standard can be obtained online at
  802. http://www.opengroup.org/unix/online.html .
  803. .PP
  804. Any typographical or formatting errors that appear
  805. in this page are most likely
  806. to have been introduced during the conversion of the source files to
  807. man page format. To report such errors, see
  808. https://www.kernel.org/doc/man-pages/reporting_bugs.html .