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