Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How to copy a Read-Only file in Linux and make the copy writable with a single cp command in Linux (Ubuntu 10.04)?

The --no-preserve and --preserve seemed to be good candidates, except that they should "and" the mode flags, while what I am looking for is something that will "or" them (add +w mode).

More details:

I have to import a repository from GIT to Perforce. I want that all Perforce depot files are Read-Only (that is how Perforce was designed), while all other files that were derived/copied from depot files are writable. Currently if a Makefile tries to copy a Read-Only file then the derived file will also be Read-only. This leads to build-errors when cp tries to overwrite Read-Only file second time. Of course the --force is a workaround here but then the derived file is also Read-Only. Also I do not want to mess with "chmod" after each "cp" command - I will do that only as the last resort.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You should look at the install command.

From man install

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
share|improve this answer
    
It seems that "install" can do what I need. I also found out that "rsync" with "--chmod" is even more superior. –  Ansis Atteka Mar 2 '11 at 3:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.