【问题标题】:copy file with destination permission使用目标权限复制文件
【发布时间】:2017-10-13 06:28:44
【问题描述】:
我们使用“cp”命令将文件从一个位置复制到另一个位置。然后,我们使用“chmod”和“chown”命令分别更改文件的权限和所有权。但是,我们可以将所有这些任务组合成一个单行命令,并且仍然得到相同的结果,而不是运行三个连续的命令。当您想要定期执行此操作或在脚本中执行此操作时,这会很有帮助。我想要这个脚本,因为我想在许多文件夹中拥有 1 个具有目标权限的文件?
【问题讨论】:
标签:
linux
bash
shell
permissions
cp
【解决方案1】:
使用 --no-preserve 保留目标模式/所有权
cp --no-preserve=mode,ownership source_file destination_file
【解决方案2】:
cp -p
来自cp之人:
-p same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST]
preserve the specified attributes (default:
mode,ownership,timestamps), if possible additional attributes:
context, links, xattr, all