Shell script code for file encoding in bulk conversion directory _linux Shell

Source: Internet
Author: User

A case of a batch conversion directory of File encoded shell script code.

Requirements Description:
As a result of turning Linux from Windows, many original win under the GBK file needs to be converted into UTF8.

The following script only judges that a UTF8 file is converted to a UTF8 file, and that the default UTF8 file is GBK, and if the file type is inconsistent, it needs to be modified.

Example:

Copy Code code as follows:

#!/bin/bash
# File Name:iconv.sh
# Author:wanggy
# site:www.jb51.net
#
Show_file ()
{
For file in ' ls $ '
Todo
If [-D $/$file];then
#目录递归调用show_file函数
Show_file "/" $file
Else
#文件
echo $ "/" $file
File_type= ' file $ '/' $file '
Type= ' echo $file _type |grep UTF-8 '
If [-Z "$type"];then
echo "is null-UTF-8 encoded, converted"
Iconv-f gbk-t UTF8 $ "/" $file-o $/"$file
Else
echo "UTF8 encoding without conversion"
Fi
Fi
Done
}
Path=./shell
Show_file $path

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.