Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have folders old and new.

I want to replace all the contents in old/* to new/*. There can be many subdirectories in those folders.

But there can be few files which are not in new/* but are in old/*, so I want them to stay as they are.

How can I do that from a Linux shell?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

rsync would probably be a better option here. It's as simple as rsync -a subdir/ ./. check this unix.stackexchage answer for better solutions

use -f with the cp command

cp -fR /source/files /dest

suppress cp to overwrite" prompt..

To override cp's alias you can simply enclose it in quotes:

 'cp' -rf ./source/* /destination/

for more information follow these links:

http://www.wallpaperama.com/forums/cp-command-problems-forcing-overwrite-using-cp-command-t5685.html

http://bytes.com/topic/unix/answers/865372-force-cp-overwrite-existing-directory

share|improve this answer

Use rsync. It will synchronize the directories in one direction. So, if you want to update your old folder with everything from new, but keep what's in there, just use:

rsync -avh --dry-run /path/to/new/ /path/to/old/

This will, in a first instance, just output the list of files that would be transferred. In that case: Everything found in new will be copied to old, unless it's already there. Everything in old stays as it is.

If it looks fine to you, remove the --dry-run argument to transmit them for real.

The -avh flags just enable archive mode (which will preserve timestamps, etc.), verbosity and human-readable file-sizes. Nothing will be deleted from the destination unless you specify the --delete flag. Consult man rsync for more information.

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.