#!/usr/local/bin/bash
toEncoding='utf-8'
# Recursive file convertion windows-1251 --> utf-8
# Place this file in the root of your site, add execute permission and run
# Converts *.php, *.html, *.css, *.js files.
# To add file type by extension, e.g. *.cgi, add '-o -name "*.cgi"' to the find command
find . -name "*.php" -o -name "*.html" -o -name "*.css" -o -name "*.js" -type f |
while read file
do
encoding=$(file -b --mime-encoding $file)
if [ $encoding != $toEncoding ]; then
echo " $file - $encoding->$toEncoding "
mv $file $file.icv
iconv -f WINDOWS-1251 -t $toEncoding $file.icv > $file
rm -f $file.icv
fi
done
file -i file.txt
iconv -f cp1251 -t utf8 исходный.txt -o конечный.txt