Wednesday 19 December 2018

diff - compare two directory trees


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?


Thanks!



Answer



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:



No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...