Using "mv" or "ditto" to merge folders in OS X
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.
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).