Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
    
It's not clear whether you are asking about preserving the source permissions or the target permissions. You've also cross-site spammed to SuperUser. –  Tom Shaw May 26 '11 at 9:00
add comment

3 Answers

up vote 8 down vote accepted

If you've only opened the manual for cp...

The next will not overwrite the file permissions and ownership + groupship:

cp --no-preserve=mode,ownership /tmp/file /home/file

Note that root privileges are needed if you want to preserve the ownership and groupship.

An excerpt from the manual:

  --preserve[=ATTR_LIST]
      preserve   the   specified   attributes   (default:  mode,owner-
      ship,timestamps), if possible  additional  attributes:  context,
      links, xattr, all
share|improve this answer
add comment

cat will work, too:

cat /tmp/file > /home/file
share|improve this answer
add comment

Or you can use even better install program from GNU coreutils that has been made for this particular purpose. Please note it is not able to recurse (no -R or -r option).

http://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html

share|improve this answer
add comment

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.