When porting JSP pages on Windows to a Linux environment, it is too slow to find a transform encoding and modifying the default encoding type, write this script to attempt file traversal ~
Long time no write, Rusty.
Copy Code code as follows:
#!/bin/bash
#
#
Spath= "/root/chengji/webroot"
Dpath= "/web"
# function Start part
Cycling () {
filelist= ' Ls-1 $SPATH '
for filename in $filelist; Todo
If [f $filename]; Then
echo Filename: $filename
/usr/bin/iconv-f gbk-t UTF-8 $SPATH/$filename-o $DPATH/$filename
#cp-PV $SPATH/$filename $DPATH/$filename This sentence is a preliminary convenience effect test
Sed-i-E ' s/gb2312/utf-8/g '-e ' s/gb2312/utf-8/g ' $DPATH/$filename
elif [D $filename]; Then
Dpath= $DPATH/$filename
MKDIR-PV $DPATH
CD $filename
Spath= ' pwd '
# Next for Recurse If you encounter a directory for self invocation ... Implement deep traversal
Cycling
# Next Usag:basename dirname
Dpath= ' DirName $DPATH '
Spath= ' DirName $SPATH '
CD $SPATH
Else
echo "File $SPATH/$filename is not a common file. Please check. "
Fi
Done
}
# Command Start section
CD $SPATH
Cycling
echo "All done."
Of course, the above code because of the use of the function loop call, significantly bloated. Here's an easy way to find:
Copy Code code as follows:
#/bin/bash
#Auth: Mo
#Desc:
#
Spath= "/root/chengji"
Dir=webroot
Dpath= "/web"
Find ${dir}-type d-exec MKDIR-PV ${dpath}/{} \;
Find ${dir}-type f-exec iconv-f gbk-t UTF-8 {}-o ${dpath/{} \;
echo "The file Next listed is isn't a common file or directory, please check."
Find ${dir}! -type f-a! -type d-ecec ls-l {} \;
Find $DPATH-type f-exec sed-i-E ' s/gb2312/utf-8/g '-e ' s/gb2312/utf-8/g ' {} \;
echo ""
echo "All done."