Skip to content

Instantly share code, notes, and snippets.

@mPastuszko
Created October 12, 2013 15:53
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mPastuszko/f521835cadd376c9d4f1 to your computer and use it in GitHub Desktop.
Correct weird encoding of Polish special characters in filenames recursively in the current directory
#!/bin/bash
replacements=\
"-e s/ą/ą/g "\
"-e s/ć/ć/g "\
"-e s/ę/ę/g "\
"-e s/ń/ń/g "\
"-e s/ś/ś/g "\
"-e s/ó/ó/g "\
"-e s/ź/ź/g "\
"-e s/ż/ż/g "
for file in `find . -type f`; do
correct_fn=$(echo "$file" | sed $replacements)
mv "$file" "$correct_fn"
done
@develth
Copy link

develth commented May 15, 2018

The following would prevent unnecessary renames:

if [ $file != $correct_fn ]
        then
          mv "$file" "$correct_fn"
fi

@secretfork
Copy link

secretfork commented Sep 25, 2018

It lacks support for whitespace in filenames. This fixes that (includes develth's "fix" as well). I added verbose (-v) to mv, feel free to remove it. Many thanks for the original idea.

find . -type f | while read file; do
  correct_fn="$(echo "$file" | sed $replacements)"
  if [ "$file" != "$correct_fn" ]; then
          mv -v "$file" "$correct_fn"
  fi
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment