How Ubuntu view and bulk modify file encoding

Source: Internet
Author: User

We all know that under Windows file encoding defaults to GBK or gb2312, but many users sometimes need to move files under Windows to the Linux system, so after the transfer is often garbled situation, this How to do? Next small series to introduce you to the next Ubuntu view and bulk Modify the file encoding method.

You can use the eNCA tool to view file encodings.

  Installation commands under Ubuntu:

sudo apt-get install eNCA

eNCA View Files

Enca-l zh_cn File View files encoding

Enca-l zh_cn-x UTF-8 File code change

Enca-l zh_cn-x UTF-8 "file1" file2 do not want to overwrite the original document

  Here is a script that changes the file encoding in bulk:

#!/bin/bash

#将文件编码更改为UTF-8

#用法

#1. Name the file encoding.sh

#2. chmod +x encoding.sh

#3. 。 /set_encoding.sh

#4. Enter directory name

#5. Enter whether to recursively change

#$1 indicates whether you want to recursively modify the file encoding

function change_file_encoing () {

For file in $ (Ls-l|awk ' {print $} ')

Todo

if [[d ' $file && $ = y]];then

CD $file

Echo $file

Change_file_encoing $

Cd..

elif [F "$file"]];then

Echo $file

Enca-l zh_cn-x UTF-8 $file

Fi

Done

#ecna-L ZH_CN file UTF-8

}

Read-p "Please enter the dir path:" Path #读取目录路径

if [!-X "$path"]; #判断目录是否存在且是否具有执行权限

Then

echo "dir Path not exists"

Else

Read-p "Please enter if you want to recursive?y/n:" Recur #是否递归

Fi

if [$recur = "Y"];

Then

CD $path

Change_file_encoing "Y" #递归修改文件编码

Else

CD $path

Change_file_encoing "n" #非递归修改

Fi

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.