#!/bin/sh
#
#Converting codepage filenames from koi8-r to utf-8
#by recursive walk by directories and use iconv for filenames.
#created by Xorader (2004)
#
ProgramName=${0##*/}
FromCharset="koi8-r"
ToCharset="utf-8"
OptV=0# be verbose
OptD=0# do proccess (not only show)
usage()
{
echo -e "Usage: ${ProgramName} [ Options ] <proccess directory>"
echo -e "There options is:"
echo -e "\t-h ... show this help"
echo -e "\t-v ... be verbosely"
echo -e "\t-d ... do proccess (not only show)"
echo -e "\t-f <charset> ... from charset (default: $FromCharset)"
echo -e "\t-t <charset> ... to charset (default: $ToCharset)"
echo -e "\n\t\t created by Xorader (2004)"
}
proccess_filename()
{
while read ifilename; do
if [ -z "$ifilename" -o "_$ifilename" == "_." ]
then
continue
fi
newfilename=`echo $ifilename | iconv -f $FromCharset -t $ToCharset`
if [ $OptD -ne 0 ]; then
mv -v "$ifilename" "$newfilename"
else
echo "$ifilename --> $newfilename"
fi
done
}
recurse_call_dir()
{
while read idirname; do
if [ -z "$idirname" -o "_$idirname" == "_." ]
then
continue
fi
recurse_walk_dir "$idirname"
if [ $OptV -ne 0 ]; then
echo -e "\treturn from \"$idirname\""
fi
cd ..
done
}
recurse_walk_dir()
{
cd "$1"
if [ $OptV -ne 0 ]; then
echo -e "\tentering \"`pwd`\" directory and see next directories:"
find . -type d -maxdepth 1
echo "########################"
fi
find . -type d -maxdepth 1 | recurse_call_dir
if [ $OptV -ne 0 ]; then
echo -e "\tOk, starting to convert filenames at \"`pwd`\" directory:"
fi
find . -maxdepth 1 | proccess_filename
if [ $OptV -ne 0 ]; then
echo "------------------------"
fi
}
while getopts "hvdf:t:" opt
do
case $opt in
v) OptV=1;;
d) OptD=1;;
f) FromCharset=$OPTARG;;
t) ToCharset=$OPTARG;;
h) usage; exit 0;;
*) usage; exit 2;;
esac
done
shift $(( $OPTIND - 1 ))
argc=$#
if [ $argc -eq 1 ]
then
DIR=$1
else
usage
exit 3
fi
recurse_walk_dir $DIR
действительно
просто я поискал минут 10 решение... потом понял что самому проще написать под мой конкретный случай (да и лишний раз попрактиковаться в shell'е никогда не повредит )
iconv --help
Usage: iconv [OPTION...] [FILE...]
Convert encoding of given files from one encoding to another.
Input/Output format specification:
-f, --from-code=NAME encoding of original text
-t, --to-code=NAME encoding for output
Information:
-l, --list list all known coded character sets
Output control:
-c omit invalid characters from output
-o, --output=FILE output file
-s, --silent suppress warnings
--verbose print progress information
-?, --help Give this help list
--usage Give a short usage message
-V, --version Print program version
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.