如何使用单个 cp 命令复制只读文件并使副本可写?

use*_*238 4 linux git perforce read-only cp

如何在 Linux 中复制只读文件并在 Linux (Ubuntu 10.04) 中使用单个 cp 命令使副本可写?

--no-preserve 和 --preserve 似乎是不错的候选者,除了它们应该“和”模式标志,而我正在寻找的是将“或”它们(添加 +w 模式)的东西。

更多细节:

我必须将存储库从 GIT 导入到 Perforce。我希望所有 Perforce 软件仓库文件都是只读的(这就是 Perforce 的设计方式),而从软件仓库文件派生/复制的所有其他文件都是可写的。目前,如果 Makefile 尝试复制只读文件,则派生文件也将是只读的。当 cp 尝试第二次覆盖只读文件时,这会导致构建错误。当然 --force 在这里是一种解决方法,但派生文件也是只读的。另外,我不想在每个“cp”命令之后都使用“chmod”——我只会把它作为最后的手段。

Maj*_*nko 8

您应该查看安装命令。

人安装

SYNOPSIS
       install [OPTION]... [-T] SOURCE DEST
       install [OPTION]... SOURCE... DIRECTORY
       install [OPTION]... -t DIRECTORY SOURCE...
       install [OPTION]... -d DIRECTORY...

DESCRIPTION
       This  install  program copies files (often just compiled) into 
       destination locations you choose.  If you want to download and install
       a ready-to-use package on a GNU/Linux system, you should instead be 
       using a package manager like yum(1) or apt-get(1).

       In the first three forms, copy SOURCE to DEST or multiple SOURCE(s) to
       the existing DIRECTORY, while setting permission modes and owner/group.
       In  the  4th form, create all components of the given DIRECTORY(ies).
...
       -m, --mode=MODE
          set permission mode (as in chmod), instead of rwxr-xr-x
Run Code Online (Sandbox Code Playgroud)