Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 5 down vote accepted

You should look at the install command.

From man install

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

       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

Make a script that will add a chmod +w after each cp? :) Only difference is that the script isn't going to be atomic, but then I don't think there are guarantees on cp atomicity wrt any included attribute changes?

share|improve this answer

Your Answer


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.