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

来源:互联网 发布:2017淘宝多肉店铺推荐 编辑:程序博客网 时间:2024/05/16 22:14

用-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::.

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 在保修期的苹果被偷了怎么办 苹果手机在保修期之外坏了怎么办 把苹果售后给的备用机摔了怎么办 把售后给的备用机摔坏了怎么办 苹果4s屏幕玻璃碎了怎么办 苹果手机摔鼓起来了屏幕花了怎么办 苹果8卡屏幕划不动了怎么办 苹果x卡屏幕划不动了怎么办 苹果5s解锁密码忘了怎么办 苹果6s屏幕摔碎了怎么办 苹果手机掉在水里了怎么办 乐视手机掉水里没法触屏了怎么办 乐视电视有声音但是黑屏怎么办 苹果手机微信语音有回音怎么办 苹果4s死机了没反应了怎么办 苹果手表的显示平坏了怎么办 苹果5s屏幕翘起来了怎么办 苹果手机圆点卡住屏幕不能动怎么办 苹果5s卡屏怎么也不动应该怎么办 苹果5s手机触摸屏太灵敏怎么办 苹果5s手机关机滑动失灵怎么办 苹果5s关机开机后没信号怎么办 苹果手机5s被弄关机了怎么办 华为荣耀5c换屏后触摸失灵怎么办 三星笔记本鼠标触摸板没反应怎么办 有米6x触摸屏不好使怎么办? 小米5s屏幕触摸没反应怎么办 苹果5s主屏幕设置没反应怎么办 华为畅享5s接听不灵怎么办 红米3s忘记锁屏密码怎么办 华为畅享5s手机打不开网络怎么办 苹果手机突然关机开不了机怎么办 苹果手机掉地上开不了机怎么办 oppo手机突然黑屏开不了机怎么办 苹果6s为什么开不了机怎么办 苹果手机还原出厂设置白苹果怎么办 捡到苹果6s手机怎么办才能自己用 苹果6s玩游戏卡住了怎么办 苹果6s进水换屏后指纹失灵怎么办 苹果手机6s声音按键失灵怎么办 苹果手机触屏失灵怎么办5s