ExperimentGarden
Taste great books and share them with your friends: Bookflavor

How to merge two directories on Mac OS X using the command line.

On Mac OS X if you use Terminal to paste a folder to a location where another folder with the same name exists then that folder will be replaced by the folder you are pasting. But what if what you want to do instead is merge the files in the existing folder with the folder you are dropping?

The easiest way to do this is to use ditto, a command line tool for accomplishing this task. For this example imagine that we have two folders:

Folder number one exists in your Downloads directory under the name "Backup" while the other exists in your Documents folder as "Work". You can use the following command to merge them:

ditto ~/Downloads/Backup ~/Documents/Work

Note that the order is important. Files in the first folder which are different from files in the second folder will be replaced by their counterparts in the second folder. Files in the first folder which are not in the second folder will remain, while files in the second folder which are not in the first folder will be copied over.
If you enjoy reading Experiment Garden, then you should subscribe by clicking here.


Be the first to reply!

You should try Duck Duck Go, the better search engine that protects your privacy.

Next > < Previous
Copyright © 2008-2010 by Experiment Garden