A bash script to check for invalid windows filenames
09.08.2020 [Software]
If you're working with FAT or NTFS file-systems alongside Linux file-systems like ext3/4, xfs, btrfs etc. and you are copying data between them, you'll sooner or later come across the problem that the DOS / Windows file-systems are more restricting when it comes to characters in filenames. The following small script checks for invalid filenames and prints them, highlighting the infringing characters.
File: find_invalid_windows_filenames.sh
#/bin/bash

# Provide the directory to check as first argument.
# If nothing is specified, use working directory.

DIRECTORY=${1}

if [ -z "${DIRECTORY}" ]; then
    DIRECTORY="."
fi

while IFS= read -r fil; do
    grep --color -E '/ |:|\\|<|>|\*|\?|\"| $' <<<${fil}
done <<<$(find "${DIRECTORY}" \( -name ' *' -o -name '* ' -o -name '*<*' -o -name '*>*' -o -name '*:*' -o -name '*\\*' -o -name '*\**' -o -name '*\?*' -o -name '*\"*' \))