Comparing Filenames in Two Directory Trees

Do you have two directory trees full of subdirectories and files? Would you like to compare the filenames to see if there are some files only in one tree or the other? If you don't have dircmp (), look at the quick-and-dirty substitute in the example below. The numbered prompts () like % are just for reference:

 [..] 
1% cd directory1 2% find . -type f -print | sort >/tmp/dir1 3% cd directory2 4% find . -type f -print | sort >/tmp/dir2 5% comm -3 /tmp/dir[12] 6% rm /tmp/dir[12]

The comm () command will give you two columns: files in the left-hand column are only in directory1. Files in the right-hand column are only in directory2. You can get other information, too, like a list of files in both trees.

This works nicely for directory trees on other computers, too. Run one find | sort on the remote system. Transfer that file to the computer with the other directory tree and run comm there. Or do the diff across the network by replacing commands 3-5 above with:

rsh 
% rsh host \ 'cd directory2; find . -type f -print | sort' | \ comm -e /tmp/dir1 -

The - argument tells comm to read its standard input (from the remote find command). Article 13.13 shows a similar trick for a filesystem across a network. Articles and are about programs that help you see a directory tree.

- JP