Score: 96
You can do this safely from Bash without overwriting anything. Here are the cleanest and most reliable ways on Arch Linux.
This tells you which filenames exist in both directories, regardless of subdirectories.
comm -12 \
<(find dir1 -type f -printf '%f\n' | sort) \
<(find dir2 -type f -printf '%f\n' | sort)
🔹 Output = filenames that appear in both directories 🔹 Safe, read-only 🔹 Ignores file content (only names)
If you want to see where the duplicates are:
for f in $(comm -12 \
<(find dir1 -type f -printf '%f\n' | sort) \
<(find dir2 -type f -printf '%f\n' | sort)); do
echo "---- $f ----"
find dir1 dir2 -type f -name "$f"
done
This helps you decide what to rename or move.
If both directories don’t have subdirectories:
ls dir1 | sort > /tmp/d1
ls dir2 | sort > /tmp/d2
comm -12 /tmp/d1 /tmp/d2
If your goal is copying files without overwriting, use:
cp -vn dir1/* dir2/
Flags:
-v → verbose-n → no clobber (won’t overwrite existing files)Helps detect same-name but different files:
find dir1 -type f -printf '%f %s\n' | sort > /tmp/a
find dir2 -type f -printf '%f %s\n' | sort > /tmp/b
comm -12 /tmp/a /tmp/b
If you just want to avoid overwriting, use method 4. If you want to audit before doing anything, use method 2.
If you want:
tell me 👍