Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 13 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:

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


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.