4

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

1

3 Answers 3

3

Use

cp -a

(archiving) or

cp -p

(preserve mode, ownership and timestamps)

2
  • 1
    Isn't this exactly what is not intended?
    – maxelost
    Commented May 26, 2011 at 16:03
  • 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
    Commented May 26, 2011 at 16:23
3

There is a better answer at ServerFault:

cp --no-preserve=all source target
1

Look at the --no-preserve option

You must log in to answer this question.

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