首页 > 教程 > Ubuntu查看和批量修改文件编码图文教程

Ubuntu查看和批量修改文件编码图文教程

时间:2016-07-06 | 来源:互联网 | 阅读:194

话题: ubuntu

我们都知道在Windows下文件编码默认为gbk或者是gb2312,但很多用户有时需要把Windows下的文件移到Linux系统中,所以转移后就经常出现乱码的情况,这该怎么办呢?接下来小编就给大家介绍下Ubuntu查看和批量修改文件编码的方法。

Ubuntu查看和批量修改文件编码图文教程

使用enca工具可以进行文件编码的查看。

Ubuntu下的安装命令:

sudo apt-get install enca

enca查看文件

enca -L zh_CN file 查看文件编码

enca -L zh_CN -x UTF-8 file 更改文件编码

enca -L zh_CN -x UTF-8 《 file1 》 file2 不想覆盖原文件

下面是一个脚本,批量更改文件编码:

#!/bin/bash

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

#用法

#1. 将文件命名encoding.sh

#2. chmod +x encoding.sh

#3. 。/set_encoding.sh

#4. 输入目录名称

#5. 输入是否递归更改

#$1表示是否要递归修改文件编码

function change_file_encoing(){

for file in $(ls -l|awk ‘{print $9}’)

do

if [[ -d “$file” && $1 = y ]];then

cd $file

echo $file

change_file_encoing $1

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” #递归修改文件编码

UbuntuV12.10 官方中文ISO镜像正式版

TOP

软件

46
Ubuntu运营中
Ubuntu:世界上最受欢迎的免费的操作系统
44.57 MB  07.16  赞(811)
安全无广告  需网络
推荐

最新好玩手游

更多

手游风云榜

更多

资讯阅读

更多


湘ICP备2022002427号-10 湘公网安备:43070202000427号
© 2013~2024 haote.com 好特网