Linux uses shell batch conversion file encoding method

  
                

Linux system operation, in addition to the use of tool conversion file encoding, but also through the shell, the use of the recursive principle of iconv function, as long as the simple shell script code, is to convert the file encoding batch.

principles: recursion, iconv

code is as follows

#! /bin/sh

TGT=“source_rst”

function fe_convert() {

for file in `ls $1`

do

if [ -d $1“/”$file ]

then

fe_convert $1“/”$file

else

mkdir -p `dirname $TGT“/”$1“/”$file`

iconv -f EUC-JISX0213 -t utf-8 $1“/”$file 》$TGT“ /”$1“/”$file

fi

done

}

fe_convert src

The above is for Linux The method of shell batch conversion file encoding is introduced. This article only has a simple code introduction, but it is more practical if it is better than tool conversion.

Copyright © Windows knowledge All Rights Reserved