If you use iTunes on multiple computers, you’ve probably run into the problem of having several copies of the same song in different places and no good way to get one consolidated library of all your songs. The method described here doesn’t merge the iTunes xml file, but it will merge all of your song files to make sure you have one copy of each song. Once you have this consolidated directory, you’ll have to re-import all of your music into iTunes.
It is wise to make sure you have a backup before trying something like this just in case something goes wrong or you execute the command in the wrong directory. As far as I’m aware there isn’t anyway to lose data using this, but backups are always a good thing.
The tool we are going to use to merge directories is called rsync and it comes with OS X. There are versions available for Windows as well, but this tutorial is going to focus on OS X. Rsync is a tool that allows you to take a source and destination directory and make the destination directory contain all of the most recent changes from both directories merged together. In doing the merge the most recent file wins.
Rsync can work over network connections so you can synchronize multiple computers without manually copy files to one machine. However, to keep things simple for this tutorial we are going to assume that all of the iTunes directories you want to sync are on the same machine and that they are called iTunes and iTunes2. We want to make iTunes contain a copy of all of the files in iTunes and iTunes2 without duplicates.
Open up a terminal window and execute the following command:
rsync /Users/me/Music/iTunes2/ /Users/me/Music/iTunes
This will take everything from the first directory (iTunes2) and combine it with all the files in the second directory (iTunes). Notice the trailing slash after the first directory (iTunes2/). This trailing slash is very important. Without it rsync will create a new directory called iTunes2 inside of iTunes which isn’t what we want.
In this example iTunes and iTunes2 are directories that have the artist directories in them. For most users the actual directories will look something like this:
rsync /Users/me/Music/iTunes2/iTunes\ Music/ /Users/me/Music/iTunes/iTunes\ Music
Notice the backslash before the space in iTunes Music. It tells the command line to treat “iTunes Music” as one directory and not two separate arguments to rsync. If you want to run rsync without touching any of your original directories, you can run the command using a new empty directory as the second argument and run the command several times with every directory you want to combine. It would look something like this:
rsync /directory1/ /new_directory
rsync /directory2/ /new_directory
rsync /directory3/ /new_directory
This would combine everything from directory1, directory2 and directory3 into the directory called new_directory. It would only put the most recent copy of each file with no duplicates, so if directory1 and directory2 had some of the same files, only the most recent one would end up in new_directory.