0

How to recursively recode all project files excluding some directories and preserving permissions?

a1111exe
  • 641
  • 4
  • 18

1 Answers1

0

Based on this question, but its solution does not preserve permissions, so I had to modify it.

WARNING: since the recursive removal is a part of the solution, use it on your own risk

Task:

Recursively recode all project files (iso8859-8 -> utf-8) excluding '.git' and '.idea' dirs and preserving permissions.

Solution (worked well in my case):

Backup your project's dir, then cd there. Run:

find . -not -path "./.git/*" -not -path "./.idea/*" -type f -print -exec iconv -f iso8859-8 -t utf-8 -o {}.converted {} \; -exec sh -c 'cat {}.converted > {}' \; -exec rm {}.converted \;

Binary and image files will fail to recode since they aren't text, so files like 'image.jpeg.converted' will be left along with 'image.jpeg'. To clean up this mess:

find . -not -path "./.git/*" -not -path "./.idea/*" -type f -regex '.*\.converted' -exec rm {} \;

Before you do that, you may want just print (without rm) to see that there are only those files listed that you'd really like to remove.

Community
  • 1
  • 1
a1111exe
  • 641
  • 4
  • 18