Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 use cp command without to overwrite target file permissions

For example

cp /tmp/file /home/file

I dont want to change chown and chgrp on /home/file

share|improve this question
    
Don't cross-post – Sathya May 26 '11 at 9:39
up vote 3 down vote accepted

Use

cp -a

(archiving) or

cp -p

(preserve mode, ownership and timestamps)

share|improve this answer
    
Isn't this exactly what is not intended? – maxelost May 26 '11 at 16:03
    
@maxelost Only if the target file exists. There's two ways to interpret the question. Copy changes permissions to the user doing the copying, and that is likely not what is intented. – Daniel Beck May 26 '11 at 16:23

There is a better answer at ServerFault:

cp --no-preserve=all source target
share|improve this answer

Look at the --no-preserve option

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .