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?

6
  • Possible duplicate of superuser.com/questions/166317/…
    – coneslayer
    Commented Jul 23, 2010 at 19:15
  • That was comparing, this is diff-ing.
    – Jonah
    Commented Jul 23, 2010 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
    Commented Jul 23, 2010 at 19:22
  • Using diff would be good, but if it can't do it other tools are just fine.
    – Jonah
    Commented Jul 23, 2010 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
    Commented Jul 23, 2010 at 19:26

1 Answer 1

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

Not the answer you're looking for? Browse other questions tagged .