Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When I copy files from one directory to another, the directory permissions get reset (e.g: from 0755 to 0775), and this causes problems, forcing me to go back and manually reset directory permissions. I'm currently doing cp -r /source/directory /destination/directory

I want to copy all of the files and new directories, but not overwrite permissions of existing directories.

share|improve this question

3 Answers 3

up vote 4 down vote accepted

To preserve links you may use cp (manpage for cp ) with the -d flag, which is equivalent to --no-dereference --preserve=links.

To combine this with the -p and -R flags you can use the archive flag -a.

share|improve this answer

Add -p flag

cp -pR /source/dir /dest/dir

-p same as --preserve=mode,ownership,timestamps

share|improve this answer

My ~/.bashrc has been modified to contain

alias cp='cp -i --preserve=all'

This means when I use cp, it will also prompt before overwriting (-i), and preserve all (i.e. mode, ownership, timestamps; and if possible additional attributes: context, links, xattr).

You could always change it to just mode instead of all if you like, but I do like having this alias to change the defaults of cp.

share|improve this answer

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.