How to compare the ls output of two folders to find a missing directory

files

I'm trying to compare a folder with 1400 subfolders to one with a 1.399. I need to know which subfolder is missing.

I tried this:

diff -rq dir1/ dir2/ | grep dir1/ | awk '{print $4}' > difference1.txt

But it's been like 6 hours yet and no output. ls in the folders is nearly instant so is there a faster approach than diff?

Best Answer

diff -u <(ls dir1) <(ls dir2)

This will make sure diff does not look inside the subdirs.

Or try this if you are brave ;)

diff -u <(find dir1/ -maxdepth 1 -type d -exec basename {} \;) <(find dir2/ -maxdepth 1 -type d -exec basename {} \;)
Related Question