I have two music libraries, one a newer version than the other. I would like to compare them to figure which files I need to copy from new music tree to old.

I have tried diff --brief -r /oldmusicdir/ /newmusicdir/ based on another user's suggestion but ^C the process after fifteen minutes (I'm guessing diff is scanning the music files themselves -- which is not necessary).

Then I tried find /oldmusicdir/ -type d | sort > oldmusicdir for old and new, then ran diff oldmusicdir newmusicdir However, since I stored the music directories in separate locations every single entry was flagged.

Next I tried running find /musicdir/ -type d | basename -s - | sort > musicdir but then my musicdir file simply read "-"

Does anyone know how to get basename to accept from STDIN? Or, does anyone have a better way of quickly comparing two music directories?



The rsync utility first popped into my mind when I saw your question. Doing something like below could quickly show what files are in directory a but not in b:

$ rsync -rcnv a/* b/

-r will recurse into the directories
-c will compare based on file checksum
-n will run it as a "dry run" and make no changes, but just print out the files 
   that would be updated
-v will print the output to stdout verbosely

This is a good option because you can compare the contents of the files as well to make sure they match. rsync's delta algorithm is optimized for this type of use case. Then if you want to make b match the contents of a, you can just remove the -n option to perform the actual sync.

Some related questions:

  • Rsync seems like a very powerful program. Definitely worth my time to get to know. Running rsync -nv --delete a/ b/ | grep deleting gave me a list of the files that existed on b but not a. Thanks! – curios Mar 28 '14 at 5:42

How about generating a recursive directory listing of each directory into separate files and then using diff on those two files?

  • Cool. Good idea, but it still does /path/albumname so all albums are flagged when I run diff since they have different paths. – curios Mar 28 '14 at 3:53
  • diff --recursive --quiet --new-file dir1/ dir2/ – Tom Hale Jul 11 '17 at 2:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.