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

Used to the Windows way of doing I just found out OS X has no merge function – moving means replacing the folder. While this does make sense, I miss merging!

I've two Wordpress directories, 1 contains default source and 2 contains worked version with plugins custom theme etc.

I want to see difference between this two, so I'm putting it on SVN. Folder 1 is already up, now in theory I should simply merge contents of 2 with 1 by replacing everything with contents of 2 but leaving hidden SVN files untouched.

Unfortunately OS X, when moving, replaces the folder so that my SVN client goes crazy and doesn't understand folder structure anymore.

So, I believe my options are mv and ditto, but which one would you use in my situation and how?

sudo mv wordpress /Documents/svn/wwwholiday/trunk/wordpress

I want mv to overwrite everything it finds, but leave alone whatever is already inside folder 1 and has no duplicate in folder 2.

share|improve this question
up vote 9 down vote accepted

The easiest way to merge folders in one way, e.g.

Merge everything from folder 1 → folder 2

would be to use rsync.

rsync -avh folder1/* folder2/

This will:

  • move all files that only exist in folder 1 and its subdirectories to folder 2
  • not overwrite anything in folder 2 if it's already there
  • overwrite files that have been changed, unless you add the --ignore-existing option
  • not delete anything from folder 2, unless you add the --delete option

Feel free to adapt this to your situation (where folder1 and folder2 are the other way round, I guess).

You can try to see what the command does by calling:

rsync -avh --dry-run folder1/ folder2/

The dry-run switch shows you what it does.

Don't forget that the backslashes have a special meaning, so folder2/ as the destination is not the same as folder2. Check the manpage of rsync for usage and more options.

Also recommended is -P (according to --help, same as --partial --progress) which adds show progress during transfer and keep partially transferred files (which is useful for retries if there was a failure).

share|improve this answer
But I do need command overwrite files. Folder 2 contains updated php files. Which need to be written over folder 1 content. Just want to retain folder 1 svn files. – Sandro Dzneladze Jun 6 '12 at 18:13
I'm sorry, of course files that have been changed will be overwritten by that command. Only files that have not been changed are skipped entirely. As long as your source folder doesn't contain SVN files, you're set. – slhck Jun 6 '12 at 18:17
@killermist The OP specifically wanted to keep SVN files as they are, which is why I included the wildcard on purpose, since without the dotglob option it'll just skip SVN directories. Of course you can exclude them from rsync by other means, but … this is for the sake of simplicity. – slhck Jun 20 '12 at 20:43

You can do this as @slhck says or you could also just use cp.

$sudo cp -R wordpress/ /Documents/svn/wwwholiday/trunk/wordpress
share|improve this answer
This creates a copy of wordpress within /Documents/svn/wwwholiday/trunk/wordpress. Did you mean wordpress/? – Daniel Beck Jun 6 '12 at 18:19
Not fixed. If the source_file ends in a /, the contents of the directory are copied rather than the directory itself. – Daniel Beck Jun 6 '12 at 18:26
Isn't that what the OP wants? – 에이바 Jun 6 '12 at 18:27
Well, yes, but you added the / to the target, not the source. – Daniel Beck Jun 6 '12 at 19:17

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.