简体   繁体   中英

Recursively recode all project files excluding some directories and preserving permissions

如何以递归方式重新编码所有项目文件( 不包括某些目录保留权限)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM