Linux系统查找替换非UTF-8编码文件的解决方法
时间:2022-10-04 03:25:27
众所周知,UTF-8是Linux系统下的一种可变长度的字符万国码,使用UTF-8码就可以支持多种语言。当某些文件并不是UTF-8编码的时候,我们可以用命令来查找替换非UTF-8码。那么,如何操作呢?跟紧跟随小编一起来看看Linux系统查找替换非UTF-8编码文件的解决方法。
UTF-8
首先,开始之前,请先安装enca这个软件包。enca是Linux等系统下用来查看文件编码和转换文件编码的工具。
下面一行Linux命令能够查找当前目录下所有文件中,哪些文件不是UTF-8编码。我对文件加了些限制,用find命令时候,排除了所有目录下的.svn目录,且只查找后缀为.php的文件。
命令1:
jw@~/sqlite>
find 。 ! -iregex ‘.*.svn.*’ -type f -name ‘*.php’ -exec bash -c “enca -L zh_CN {}|grep GB2312 》 /dev/null && echo {}” ;
./sqlite_utility.php
./sqlite_result.php
./sqlite_forge.php
./sqlite_driver.php
既然找到了这些非UTF8编码的文件,接下来再用一条命令将他们都转换成UTF8编码。
命令2:
jw@~/sqlite>
find . ! -iregex ‘.*.svn.*’ -type f -name ‘*.php’ -exec bash -c “enca -L zh_CN {} | grep GB2312 》/dev/null && enconv -L zh_CN -x UTF-8 {}” ;
当你用命令2 全部转换完成后,如果你期待命令1的输出为空,那么你就错了。实际上英语字母的utf8编码和ASCII编码是一样的。当一个全是英文字母的文件用UTF8 w/o BOM编码保存,那么enca会识别他是一个ACSII编码的文件。所以,你猜到了,命令2做了一些无用功。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Win7系统重装账户被禁用怎么办?
![](https://img.aspxhome.com/file/2023/26/a227977_0s.png)
Curio Professional 13 有哪些新功能?Curio Professional功能特色介绍
![](https://img.aspxhome.com/file/2023/8/a213208_0s.png)
Win7系统兼容性如何设置?
![](https://img.aspxhome.com/file/2023/4/a311570_0s.jpg)
戴尔电脑Win10触摸板怎么关闭?
![](https://img.aspxhome.com/file/2023/2/51062_0s.jpg)
win10系统如何通过PID号结束进程
![](https://img.aspxhome.com/file/2023/5/a317065_0s.png)
苹果Mac电脑缓存如何清理?
![](https://img.aspxhome.com/file/2023/1/a208481_0s.jpeg)
形色识花怎么删记录?形色识花删记录的方法
![](https://img.aspxhome.com/file/2023/7/a332504_0s.jpg)
excel表格中如何换行?
![](https://img.aspxhome.com/file/2023/7/a167927_0s.gif)
Outlook邮箱怎么注册?Outlook邮箱注册方法
![](https://img.aspxhome.com/file/2023/9/a340578_0s.jpg)
Word2013中的波浪线怎么删除?
![](https://img.aspxhome.com/file/2023/9/25299_0s.jpg)
WIN7系统怎么关闭智能卡服务?
![](https://img.aspxhome.com/file/2023/28/a249288_0s.jpg)
Win10系统电脑声音一会大一会小的解决方法
![](https://img.aspxhome.com/file/2023/3/a297252_0s.jpg)
Win7定时关机怎么设置? Win7设置定时关机的方法
![](https://img.aspxhome.com/file/2023/27/a232789_0s.jpg)
为什么excel输入数字会变_excel输入数字变化的解决方法
![](https://img.aspxhome.com/file/2023/30/a268190_0s.png)
Curvy3D for Mac如何制作弯曲的球体?
![](https://img.aspxhome.com/file/2023/1/a212271_0s.png)
win10系统开启管理员权限的方法
![](https://img.aspxhome.com/file/2023/2/a291048_0s.png)
如何确定我的Mac或Linux是否易受到Shellshock攻击?
![](https://img.aspxhome.com/file/2023/6/a215466_0s.jpg)
Win10系统没有开始菜单怎么解决?
![](https://img.aspxhome.com/file/2023/4/a310772_0s.jpg)
微软日语输入法怎么默认平假名?微软日语输入法使用教程
![](https://img.aspxhome.com/file/2023/1/a271867_0s.png)
excel如何设置打印区域呢?打印区域介绍
![](https://img.aspxhome.com/file/2023/2/40932_0s.jpg)