6/02/2021

Bash Script to Rename all Files and Folders Containing Special Characters

Apparently, Sonos still does not fully support SMB v3, it has problems with files and folders containing special characters, in my case umlauts.

The script below renames all of the "offending" items, you can easily adapt it to your purposes. Hope you find it useful.


find . -depth -regex '.*[äöüÄÖÜß].*' 2>/dev/null | while read FILE ; do
  dir=`dirname "${FILE}"`;
  oldfile=`basename "${FILE}"`;
  if [[ ${oldfile} =~ .*[äöüÄÖÜß].* ]]; then
    newfile=`echo ${oldfile} | sed -e 's/Ä/Ae/g;s/ä/ae/g;s/Ö/Oe/g;s/ö/oe/g;s/Ü/Ue/g;s/ü/ue/g;s/ß/ss/g'`;
    mv "${dir}/${oldfile}" "${dir}/${newfile}";
  fi;
done

A note to Sonos: your posh brand should really not be relying on SMB v1 any more. It's 20201, guys, and some people do care about their security! But I guess I have to consider myself lucky for being able to connect to my server at all, as it requires v3.

No comments:

adaxas Web Directory