HOWTO Merge Folder Trees (...using the command line)

There comes a time when you need to do this sort of thing and the default behavior (which is to completely replace folder contents, rather than merge them as in ) just gets in the way.

Regardless of the reasons for this behavior and its counter-intuitiveness for those not accustomed to the way, it’s sometimes necessary to merge two folder trees with the minimum of fuss, and there are three ways to do it:

# The standard UNIX way
cp -R -v source/. destination
# The geeky UNIX way (restartable)
rsync -vaEW source/ destination
# The OSX "easy" way
ditto -V source destination

Pedro Melo pointed out that the second way is restartable and can save you quite some time – I added the W flag because I do this most often inside the same filesystems and the extra checksumming done by rsync makes it a bit slower.

ditto is my preferred way because it’s just simpler, and is one of the hidden gems of the environment given its many other uses (man ditto for details).

This page is referenced in:

  • HOWTONov 18th 2006