cp 不覆盖目标权限

Dav*_*vid 31 linux cp

如何在cp不更改目标文件权限的情况下使用该命令?例如:

cp /tmp/file   /home/file
Run Code Online (Sandbox Code Playgroud)

我不想改变chownchgrp/home/file

Lek*_*eyn 36

如果您只打开手册cp...

接下来不会覆盖文件权限和所有权+组权:

cp --no-preserve=mode,ownership /tmp/file /home/file
Run Code Online (Sandbox Code Playgroud)

请注意,如果您想保留所有权和组权,则需要 root 权限。

手册摘录:

  --preserve[=ATTR_LIST]
      preserve   the   specified   attributes   (default:  mode,owner-
      ship,timestamps), if possible  additional  attributes:  context,
      links, xattr, all
Run Code Online (Sandbox Code Playgroud)

  • 不完全是作者想要的。如果在`--preserve`(或其别名)之后使用`--no-preserve` 才有意义,否则它不会影响`cp` 的行为。作者想保持现有目标文件的文件模式,只覆盖其内容 (2认同)

Cak*_*mox 12

cat 也会起作用:

cat /tmp/file > /home/file
Run Code Online (Sandbox Code Playgroud)