Cp + not want to overwrite permissions

4

0

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

david

Posted 2011-05-26T07:21:56.237

Reputation: 65

Don't cross-post

– Sathyajith Bhat – 2011-05-26T09:39:39.943

Answers

3

Use

cp -a

(archiving) or

cp -p

(preserve mode, ownership and timestamps)

Daniel Beck

Posted 2011-05-26T07:21:56.237

Reputation: 98 421

1Isn't this exactly what is not intended? – maxelost – 2011-05-26T16:03:00.270

1@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 – 2011-05-26T16:23:46.457

3

There is a better answer at ServerFault:

cp --no-preserve=all source target

Joss

Posted 2011-05-26T07:21:56.237

Reputation: 61

1

Look at the --no-preserve option

zvrba

Posted 2011-05-26T07:21:56.237

Reputation: 160