使用目标权限复制文件



我们使用"cp"命令将文件从一个位置复制到另一个位置。然后,我们使用"chmod"和"chown"命令分别更改文件的权限和所有权。但是,我们可以将所有这些任务组合到一个单行命令中,并且仍然得到相同的结果,而不是运行三个连续的命令。当您想要定期或在脚本中执行此操作时,这会很有帮助。我想要这个脚本,因为我想在具有目标权限的许多文件夹中 1 个文件?

使用 --

no-preserve 来保留目标模式/所有权

cp --no-preserve=mode,ownership source_file destination_file
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

最新更新