このスクリプトは、異なる(サブ)ディレクトリにある場合やファイル拡張子が異なる(または拡張子がまったくない)場合でも、同じファイル名のすべてのファイルを一覧表示します。
declare -A array=() dupes=()
while IFS= read -r -d '' file; do
base=${file##*/} base=${base%.*}
if [[ ${array[$base]} ]]; then
dupes[$base]+=" $file"
else
array[$base]=$file
fi
done < <(find /the/dir -type f -print0)
for key in "${!dupes[@]}"; do
echo "$key: ${array[$key]}${dupes[$key]}"
done
(ソース)
まったく同じことをしたいのですが、同じファイル名のファイルを大文字と小文字を区別して一覧表示します。これは、これらすべてのファイルが重複としてリストされる場所を意味します。
/the/dir/file.txt
/the/dir/folder1/File
/the/dir/folder2/filE.JPG