The CP command retains the appropriate permissions for the original file

Source: Internet
Author: User
Tags mkdir symlink

With the-p or-a parameter

eg

--preserve=mode,ownership,timestamps

$info CP

'-A '
'--archive '
Preserve as much as possible of the structure and attributes of the
Original files in the copy (but don't attempt to preserve internal
directory structure; i.e., ' ls-u ' may list the entries in a copied
Directory in a different order). Try to preserve SELinux security
Context and Extended attributes (xattr), but ignore any failure to
Do and print no corresponding diagnostic. Equivalent to '-DR
--preserve=all ' with the reduced diagnostics.


'-d '
Copy Symbolic links as symbolic links rather than copying the files
That's they point to, and preserve hard links between source files in
The copies. Equivalent to '--no-dereference--preserve=links '.


'-P '
'--preserve[=attribute_list] '
Preserve the specified attributes of the original files. If
Specified, the attribute_list must be a comma-separated LIST of one
Or more of the following strings:


' Mode '
Preserve the file mode bits and access control lists.
' Ownership '
Preserve the owner and group. On most modern systems
Users with appropriate privileges could change the owner of a
File, and ordinary users may preserve the group ownership of a
File only if they happen to being a member of the desired group.
' Timestamps '
Preserve The Times of last access and last modification, when
Possible. On older systems, it isn't possible to preserve
These attributes the affected file is a symbolic link.
However, many systems now provide the ' Utimensat ' function,
Which makes it possible even for symbolic links.
' Links '
Preserve in the destination files any links between
corresponding source files. With '-l ' or '-h ', this
Option can convert symbolic links to hard links. For example,
$ mkdir C; : > A; Ln-s a B; Cp-ah a b C; Ls-i1 C
74161745 A
74161745 b
Note the inputs: ' B ' are a symlink to regular file ' a ', yet the
Files in destination directory, '/', are hard-linked. Since
'-a ' implies '--no-dereference ' it would copy the symlink, but
The later '-H ' tells ' CP ' to Dereference's command line
Arguments where it then sees two files with the same inode
Number. Then the '--preserve=links ' option also implied by
'-a ' would preserve the perceived hard link.


Here are a similar example that exercises ' CP '-l ' option:
$ mkdir b C; (CD B;: > A; ln-s a b); Cp-al b C; Ls-i1 c/b
74163295 A
74163295 b


' Context '
Preserve SELinux Security context of the file, or fail with
Full diagnostics.
' Xattr '
Preserve extended attributes of the file, or fail with full

Diagnostics. If ' CP ' is built without xattr support, ignore
This option. If SELinux context, ACLs or capabilities are
Implemented using Xattrs, they are preserved implicitly by
This option as a, i.e., even without specifying
'--preserve=mode ' or '--preserve=context '.
' All '
Preserve all file attributes. Equivalent to specifying all of
The above, but with the difference this failure to preserve
SELinux or extended attributes does not
Change ' CP ' s exit status. In contrast to '-a ', all but
' Operation not supported ' warnings are output.


Using '--preserve ' with no attribute_list are equivalent to
'--preserve=mode,ownership,timestamps '.


In the absence of this option, the permissions of existing
Destination files are unchanged. Each new file was created with the
mode of the corresponding source file minus the Set-user-id,
Set-group-id, and sticky bits as the Create mode; The operating
System then applies either the Umask or a default ACL, possibly
resulting in a more restrictive file mode. *note File
Permissions::.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.