Develop/Linux
[Linux] 폴더내 파일 인코딩 바꾸기
시크라기
2012. 5. 2. 17:50
# filename: euckr2utf8.sh # usage: ./euckr2utf8.sh source target # made by Heesung SHIN (ensual@gmail.com) # #!/bin/bash recurse () { rm -rf $2 echo make the directory $2 mkdir $2 for file in $(ls $1) do name="$1/$file" echo -n "$2/$file" | iconv -fcp949 -tutf8 -o temp # change the encoding of the name of file for newname in $(cat temp) do if [ -d $name ]; then recurse $name $newname else echo convert $file to $newname iconv -fcp949 -tutf8 $name -o $newname # change the encoding of the content of file if [ $? -ne 0 ]; then echo "-->" copy the $file to $newname cp $name $newname fi fi done ; done ; } recurse $1 $2 rm temp위 함수를 이용해서 변경해주면됨.
$ ./[bash_file_name].sh [src_folder] [dest_folder]
또는 아래 스크립트로도 가능함.
#!/bin/sh from=$1 to=$2 // search files target_dir=$3 target_files=$(find $target_dir -type f \( -name "*.php" -or -name "*.html" -or -name "*.css" -or -name "*.js" \)) for file in $target_files;do iconv -c -f=$from -t=$to $file > $file.tmp && mv -f $file.tmp $file done exit 0
$ ./[bash_file_name].sh [src_encoding] [dest_encoding] [src_directory]