I want to make a virtual file system from a few folders and want to check if there are any conflicting files. So I want to provide a few folders and get files with the same path relative to their folders.
How can I find the conflicts?
#!/usr/bin/env bash
# Find conflicting paths in multiple folders to use with mergerfs
# Usage: ./conflict.sh /path/to/folder1 /path/to/folder2 /path/to/folder3 > conflicts.txt
find_conflicting_files() {
local folders=("$@")
local files=()
if [[ ${#folders[@]} -lt 2 ]]; then
echo "Please provide at least 2 folders"
exit 1
fi
for folder in "${folders[@]}"; do
files+=("$(find "$folder" -type f)")
done
# find all conflicting files
# print the conflicting files
for conflict in "${conflicts[@]}"; do
echo "$conflict"
done
find dir1 dir2 -printf '%P\n' | sort | uniq -d