cp命令保持原来文件的相应权限

用-p 或-a参数

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 do not 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 that 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 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, only
          users with appropriate privileges may change the owner of a
          file, and ordinary users may preserve the group ownership of a
          file only if they happen to be a member of the desired group.
     ‘timestamps’
          Preserve the times of last access and last modification, when
          possible.  On older systems, it is not possible to preserve
          these attributes when 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.  Note that 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’ is a symlink to regular file ‘a’, yet the
          files in destination directory, ‘c/’, are hard-linked.  Since
          ‘-a’ implies ‘--no-dereference’ it would copy the symlink, but
          the later ‘-H’ tells ‘cp’ to dereference the command line
          arguments where it then sees two files with the same inode
          number.  Then the ‘--preserve=links’ option also implied by
          ‘-a’ will preserve the perceived hard link.


          Here is a similar example that exercises ‘cp’’s ‘-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 well, 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 that failure to preserve
          SELinux security context 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 is equivalent to
     ‘--preserve=mode,ownership,timestamps’.


     In the absence of this option, the permissions of existing
     destination files are unchanged.  Each new file is 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::.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值