Compare content of two folders, including subfolders

Terminal: diff

You can compare two folders in Terminal using the following command:

diff -rq /path/to/folder1 /path/to/folder2

To ignore folder hierarchy you can copy all the files out of a folder into a third folder, then compare these:

find /path/to/folder2 -mindepth 2 -type f -print -exec cp {} /path/to/folder3 \;

This is an old thread, I realise, but it looks like the question wasn't fully answered. I stumbled across this before trying to figure out roughly the same things for myself, so I thought I'd post an option in case others stumble across it...

Some of the answers were nearly there... and mine might be done more easily, but it works!

This will create a file of all the names of your photos:

find /Path/to/the/topmost folder/of/photos -mindepth 2 -type f -print | sed 's/^.*///' | sort > /tmp/photos-from-folders

If any are in folders owned by others, prepend with sudo and use >> to append those filenames to those already in the initial file.

use a similar command to create a second file containing all the filenames of your phone's photos.

You can just do a diff and send to a file with > or, if you know which set is biggest, use that as file1 and do

diff file1 file2 | egrep -v '<' > filediff-output

Of course, all the paths have been stripped by the sed in the intial find to generate just the filenames. If you see something that might be missing, you want to know where it is, so use

sudo find /Path/to/the/topmost folder/of/photos -name 'filename-you-want' -ls

and that will tell you where it is.

Hope this helps. I helped me work out what I need to keep from an old home directory of mine that's not in my new home directory. 65 Gig of space saved!