2

Possible Duplicate:
Linux: Compare Directory Structure Without Comparing Files

I am diff-ing two folder trees, but it takes a long time because it is diff-ing the files themselves. I just want to know what folders/files are in one tree and not the other.

What is the best way to do this?

Jonah
  • 915
  • 1
  • 10
  • 12
  • Possible duplicate of http://superuser.com/questions/166317/linux-compare-directory-structure-without-comparing-files – coneslayer Jul 23 '10 at 19:15
  • That was comparing, this is diff-ing. – Jonah Jul 23 '10 at 19:19
  • @Jonah - are you asking how to do it, specifically with diff, when the other question was open to other tools and commands? – Gnoupi Jul 23 '10 at 19:22
  • Using diff would be good, but if it can't do it other tools are just fine. – Jonah Jul 23 '10 at 19:26
  • 3
    I don't understand the distinction you're making between "comparing" and "diffing". The solution that you accepted in the other question used diff as a final step, and should tell you "what folders/files are in one tree and not the other". Can you clarify what you need that it doesn't give you? – coneslayer Jul 23 '10 at 19:26
  • Ah, I was confused as to how the provided bash script works (I'm evidently new to this), and was running it with a typo. The output was strange, and I thought it was for a side by side comparison or something. I'll delete this question. Thanks for the help! – Jonah Jul 23 '10 at 19:54

1 Answers1

7

Use find to list the files in each tree, sort them, then use diff or comm for comparison. The little-known comm command is a specialized file comparison tool that just distinguishes lines appearing only in the first file, lines appearing only in the second file and lines appearing in both files.

(cd /some/dir1 && find . | sort >/tmp/dir1.find)
(cd /where/dir2 && find . | sort >/tmp/dir2.find)
# Show the files that are in dir1 but not in dir2
comm -23 /tmp/dir1.find /tmp/dir2.find
# Show the files that are in dir2 but not in dir1
comm -13 /tmp/dir1.find /tmp/dir2.find
Gilles 'SO- stop being evil'
  • 69,786
  • 21
  • 137
  • 178