| 
 
 
 
 
	在将windows上的jsp网页移植到linux环境中时,发现一个个的转换编码及修改默认编码类型太慢,写此脚本进行尝试文件遍历~ 
	好久不写,手生了。 
	  
 
	
		
			#!/bin/bash
		
			#
		
			#
		
			SPATH="/root/chengji/WebRoot"
		
			DPATH="/web"
		
			 
		
			# 函数开始部分
		
			CYCLING(){ 
		
			 filelist=`ls -1 $SPATH` 
		
			 
		
			for filename in $filelist ; do
		
			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 该句为前期便利效果测试
		
			       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 如果遇到目录进行自我调用。。。实现深层遍历
		
			       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 
		
			} 
		
			 
		
			# 命令开始部分
		
			cd $SPATH 
		
			CYCLING 
		
			echo "All Done." 
	当然,上面的代码由于使用了函数循环调用,显的很臃肿。下面来一种简单的方法,find一下: 
 
	(责任编辑:IT)
		
			#/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 not 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." |