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::.
- cp命令保持原来文件的相应权限
- 关于 非文件所有者 使用cp命令后 文件权限的问题
- cp 拷贝文件保持源文件的时间属性
- shell 中cp命令的简单实现(未考虑复制后文件的权限)
- cp命令复制时,保持路径不变
- linux命令之文件的复制(CP)
- 文件复制命令CP 的简单实现
- 文件读写,cp命令的实现
- Linux文件复制cp命令的实现
- 文件时间对于CP命令的影响
- 远程cp文件命令
- cp 复制文件命令
- 环境变量,mv命令,cp命令,几个查看文件的命令
- cp 命令的用法
- java的cp命令
- java的cp命令
- LINUX的cp命令
- Linux 的cp命令
- JSTL标签
- Redis中multi,exec,watch,发布与订阅模式命令介绍笔记(9)
- C面向对象-单例模式
- VirtualBox COM获取对象失败
- EL表达式
- cp命令保持原来文件的相应权限
- 暑期小白关于编程的一些收获
- 总结
- unity学习之飞机大战制作 关键点(六) 子弹与敌机之间的碰撞
- 怎样判断一个网站或域名被K过
- 泛型类、泛型方法、通配符泛型、通配符的超类型限定
- 3781 -- Paint the Grid Reloaded
- 自媒体平台列表
- FFMPEG之库文件及头文件