The accepted answer will also list the files that exist in both directories, but arehave different content. To list onlyONLY the files that exist in dir1 you can use:
diff -r dir1 dir2 | grep 'Only in' | grep dir1 | awk '{print $4}' > difference1.txt
Explanation:
- diff -r dir1 dir2 : compare
- grep 'Only in': get lines that contain 'Only in'
- grep dir1 : get lines that contain dir