Thursday, November 17, 2011

Comparing Directory Structures


I often face a problem, spend significant amounts of time finding the solution, apply the solution, and then forget it. And when I face the same problem later on, I remember I knew the solution once, but have long forgotten it by then. And I ask myself:

How the Hell did I do that?

Hence this blog. And for my first post, directory structure comparison. Handy for anyone who wants to keep data synced across external hard drives, or who wants to make sure that a big copy procedure went well. This is linux-based, it also works on Mac OS X, here goes:
  1. find /path1 -exec basename {} \; | sort > file1
  2. find /path2 -exec basename {} \; | sort > file2
  3. # at this point you can use diff file1 file2
  4. # or
  5. # here we want files only listed in file1 but not in file2
  6. comm -23 file1 file2
  7. # here we show files listed in file2 but not in file1
  8. comm -23 file2 file1
And the be-nice reference link to where I found it:

No comments:

Post a Comment