Linux中如何查看文件编码及对文件进行编码转换

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux中如何查看文件编码及对文件进行编码转换相关的知识,希望对你有一定的参考价值。

查看文件编码
在Linux中查看文件编码可以通过以下几种方式:
1.在Vim中可以直接查看文件编码
:set fileencoding
即可显示文件编码格式。
如果你只是想查看其它编码格式的文件或者想解决用Vim查看文件乱码的问题,那么你可以在
~/.vimrc 文件中添加以下内容:

set encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936

这样,就可以让vim自动识别文件编码(可以自动识别UTF-8或者GBK编码的文件),其实就是依照fileencodings提供的编码列表尝试,如果没有找到合适的编码,就用latin-1(ASCII)编码打开。

文件编码转换
1.在Vim中直接进行转换文件编码,比如将一个文件转换成utf-8格式
:set fileencoding=utf-8
2. iconv 转换,iconv的命令格式如下:
iconv -f encoding -t encoding inputfile
比如将一个UTF-8 编码的文件转换成GBK编码
iconv -f GBK -t UTF-8 file1 -o file2

iconv -f gbk -t utf8 linux常用命令.txt > linux常用命令.txt.utf8

文件名编码转换:

从Linux 往 windows拷贝文件或者从windows往Linux拷贝文件,有时会出现中文文件名乱码的情况,出现这种问题的原因是因为,windows的文件名 中文编码默认为GBK,而Linux中默认文件名编码为UTF8,由于编码不一致,所以导致了文件名乱码的问题,解决这个问题需要对文件名进行转码。

在Linux中专门提供了一种工具convmv进行文件名编码的转换,可以将文件名从GBK转换成UTF-8编码,或者从UTF-8转换到GBK。

首先看一下你的系统上是否安装了convmv,如果没安装的话用:
yum -y install convmv
安装。

下面看一下convmv的具体用法:

convmv -f 源编码 -t 新编码 [选项] 文件名

常用参数:
-r 递归处理子文件夹
--notest 真正进行操作,请注意在默认情况下是不对文件进行真实操作的,而只是试验。
--list 显示所有支持的编码
--unescap 可以做一下转义,比如把%20变成空格
比如我们有一个utf8编码的文件名,转换成GBK编码,命令如下:

convmv -f UTF-8 -t GBK --notest utf8编码的文件名
这样转换以后"utf8编码的文件名"会被转换成GBK编码(只是文件名编码的转换,文件内容不会发生变化)
参考技术A file xxx
转换用convert命令

在Linux中对文件的编码及对文件进行编码转换操作

参考:https://www.cnblogs.com/mithrilon/archive/2018/06/03/9082449.html

http://blog.chinaunix.net/uid-25266990-id-2853835.html

1、如果发现Linux的文件不是utf8格式的文件,首先需要检测文件编码格式,在Centos7安装enca,需要联网的说。

 1 [root@slaver1 ~]# yum install enca
 2 已加载插件:fastestmirror, langpacks
 3 Loading mirror speeds from cached hostfile
 4  * base: mirror.bit.edu.cn
 5  * epel: mirrors.tuna.tsinghua.edu.cn
 6  * extras: mirror.bit.edu.cn
 7  * updates: mirrors.tuna.tsinghua.edu.cn
 8 正在解决依赖关系
 9 --> 正在检查事务
10 ---> 软件包 enca.x86_64.0.1.19-1.el7 将被 安装
11 --> 解决依赖关系完成
12 
13 依赖关系解决
14 
15 ================================================================================================================================================================================================================================
16  Package                                             架构                                                  版本                                                       源                                                   大小
17 ================================================================================================================================================================================================================================
18 正在安装:
19  enca                                                x86_64                                                1.19-1.el7                                                 epel                                                107 k
20 
21 事务概要
22 ================================================================================================================================================================================================================================
23 安装  1 软件包
24 
25 总下载量:107 k
26 安装大小:311 k
27 Is this ok [y/d/N]: y
28 Downloading packages:
29 enca-1.19-1.el7.x86_64.rpm                                                                                                                                                                               | 107 kB  00:00:03     
30 Running transaction check
31 Running transaction test
32 Transaction test succeeded
33 Running transaction
34   正在安装    : enca-1.19-1.el7.x86_64                                                                                                                                                                                      1/1 
35   验证中      : enca-1.19-1.el7.x86_64                                                                                                                                                                                      1/1 
36 
37 已安装:
38   enca.x86_64 0:1.19-1.el7                                                                                                                                                                                                      
39 
40 完毕!
41 [root@slaver1 ~]# 

 

2、使用方式,最常用的使用方式,判断该文件的字符集格式,如下所示:

1 [root@slaver1 soft]# enca aaa.txt 
2 Unrecognized encoding
3 [root@slaver1 soft]# 

我们需要看看当前系统下 enca 支持的语言和对应的编码类型:

 1 [root@slaver1 soft]# enca --list languages
 2 belarusian: CP1251 IBM866 ISO-8859-5 KOI8-UNI maccyr IBM855 KOI8-U
 3  bulgarian: CP1251 ISO-8859-5 IBM855 maccyr ECMA-113
 4      czech: ISO-8859-2 CP1250 IBM852 KEYBCS2 macce KOI-8_CS_2 CORK
 5   estonian: ISO-8859-4 CP1257 IBM775 ISO-8859-13 macce baltic
 6   croatian: CP1250 ISO-8859-2 IBM852 macce CORK
 7  hungarian: ISO-8859-2 CP1250 IBM852 macce CORK
 8 lithuanian: CP1257 ISO-8859-4 IBM775 ISO-8859-13 macce baltic
 9    latvian: CP1257 ISO-8859-4 IBM775 ISO-8859-13 macce baltic
10     polish: ISO-8859-2 CP1250 IBM852 macce ISO-8859-13 ISO-8859-16 baltic CORK
11    russian: KOI8-R CP1251 ISO-8859-5 IBM866 maccyr
12     slovak: CP1250 ISO-8859-2 IBM852 KEYBCS2 macce KOI-8_CS_2 CORK
13    slovene: ISO-8859-2 CP1250 IBM852 macce CORK
14  ukrainian: CP1251 IBM855 ISO-8859-5 CP1125 KOI8-U maccyr
15    chinese: GBK BIG5 HZ
16       none:
17 [root@slaver1 soft]# 

 

3、转换文件编码格式,在知道了文件的正确编码格式之后, 我们往往会希望将文件转换为UTF8之类常用或者系统默认支持的编码格式, 以便后续进一步处理,使用 enca 进行转换。

当我们给 enca 命令添加-x参数时,enca 命令就会将文件转换为-x参数指定的编码格式。

1 [root@slaver1 soft]# enca -L chinese aaa.txt 
2 Unrecognized encoding
3 [root@slaver1 soft]# enca -i -L chinese aaa.txt 
4 ???
5 [root@slaver1 soft]# enca -x UTF8 -L chinese aaa.txt 
6 [root@slaver1 soft]# enca -L chinese aaa.txt 
7 Unrecognized encoding
8 [root@slaver1 soft]# 

貌似我这里做的操作,不好使的样子,算了,还是使用linux自带iconv 进行转换的操作吧。

 

4、iconv 是*nix系统里的转换字符编码的标准命令和API,如果我们希望将一个GBK编码的文件转换为UTF8编码, 可以以以下方式使用 iconv 命令。

1 [root@slaver1 soft]# iconv -f GBK -t UTF8 aaa.txt 
2 [root@slaver1 soft]# 

其中aaa.txt是要被转换的文件, -f GBK参数表示源文件的编码是GBK,-t UTF8则表示要转换的目标编码。 执行以上命令后,iconv 命令会将转换后的文件内容打印到标准输出。

如果希望将转换后的内容保存到文件(iconv -f GBK -t UTF8 -o aaa_converted.txt aaa.txt 很好用的命令,如果服务器是GBK的,但是此服务器生成的文件要传输到UTF8服务器上面,要进行转义之后才可以进行操作,不然会报错误的), 可以添加-o参数:

1 [root@slaver1 soft]# iconv -f GBK -t UTF8 -o aaa_converted.txt aaa.txt 
2 [root@slaver1 soft]# 

这个命令就会将转换后的内容自动保存到 aaa_converted.txt 文件,通过 iconv -l则可以查看所有的字符集名称.。前文也提到enca -i则可以用来输出 iconv 可用的文件编码名。

  1 [root@slaver1 soft]# iconv -l
  2 The following list contain all the coded character sets known.  This does
  3 not necessarily mean that all combinations of these names can be used for
  4 the FROM and TO command line parameters.  One coded character set can be
  5 listed with several different names (aliases).
  6 
  7   437, 500, 500V1, 850, 851, 852, 855, 856, 857, 860, 861, 862, 863, 864, 865,
  8   866, 866NAV, 869, 874, 904, 1026, 1046, 1047, 8859_1, 8859_2, 8859_3, 8859_4,
  9   8859_5, 8859_6, 8859_7, 8859_8, 8859_9, 10646-1:1993, 10646-1:1993/UCS4,
 10   ANSI_X3.4-1968, ANSI_X3.4-1986, ANSI_X3.4, ANSI_X3.110-1983, ANSI_X3.110,
 11   ARABIC, ARABIC7, ARMSCII-8, ASCII, ASMO-708, ASMO_449, BALTIC, BIG-5,
 12   BIG-FIVE, BIG5-HKSCS, BIG5, BIG5HKSCS, BIGFIVE, BRF, BS_4730, CA, CN-BIG5,
 13   CN-GB, CN, CP-AR, CP-GR, CP-HU, CP037, CP038, CP273, CP274, CP275, CP278,
 14   CP280, CP281, CP282, CP284, CP285, CP290, CP297, CP367, CP420, CP423, CP424,
 15   CP437, CP500, CP737, CP770, CP771, CP772, CP773, CP774, CP775, CP803, CP813,
 16   CP819, CP850, CP851, CP852, CP855, CP856, CP857, CP860, CP861, CP862, CP863,
 17   CP864, CP865, CP866, CP866NAV, CP868, CP869, CP870, CP871, CP874, CP875,
 18   CP880, CP891, CP901, CP902, CP903, CP904, CP905, CP912, CP915, CP916, CP918,
 19   CP920, CP921, CP922, CP930, CP932, CP933, CP935, CP936, CP937, CP939, CP949,
 20   CP950, CP1004, CP1008, CP1025, CP1026, CP1046, CP1047, CP1070, CP1079,
 21   CP1081, CP1084, CP1089, CP1097, CP1112, CP1122, CP1123, CP1124, CP1125,
 22   CP1129, CP1130, CP1132, CP1133, CP1137, CP1140, CP1141, CP1142, CP1143,
 23   CP1144, CP1145, CP1146, CP1147, CP1148, CP1149, CP1153, CP1154, CP1155,
 24   CP1156, CP1157, CP1158, CP1160, CP1161, CP1162, CP1163, CP1164, CP1166,
 25   CP1167, CP1250, CP1251, CP1252, CP1253, CP1254, CP1255, CP1256, CP1257,
 26   CP1258, CP1282, CP1361, CP1364, CP1371, CP1388, CP1390, CP1399, CP4517,
 27   CP4899, CP4909, CP4971, CP5347, CP9030, CP9066, CP9448, CP10007, CP12712,
 28   CP16804, CPIBM861, CSA7-1, CSA7-2, CSASCII, CSA_T500-1983, CSA_T500,
 29   CSA_Z243.4-1985-1, CSA_Z243.4-1985-2, CSA_Z243.419851, CSA_Z243.419852,
 30   CSDECMCS, CSEBCDICATDE, CSEBCDICATDEA, CSEBCDICCAFR, CSEBCDICDKNO,
 31   CSEBCDICDKNOA, CSEBCDICES, CSEBCDICESA, CSEBCDICESS, CSEBCDICFISE,
 32   CSEBCDICFISEA, CSEBCDICFR, CSEBCDICIT, CSEBCDICPT, CSEBCDICUK, CSEBCDICUS,
 33   CSEUCKR, CSEUCPKDFMTJAPANESE, CSGB2312, CSHPROMAN8, CSIBM037, CSIBM038,
 34   CSIBM273, CSIBM274, CSIBM275, CSIBM277, CSIBM278, CSIBM280, CSIBM281,
 35   CSIBM284, CSIBM285, CSIBM290, CSIBM297, CSIBM420, CSIBM423, CSIBM424,
 36   CSIBM500, CSIBM803, CSIBM851, CSIBM855, CSIBM856, CSIBM857, CSIBM860,
 37   CSIBM863, CSIBM864, CSIBM865, CSIBM866, CSIBM868, CSIBM869, CSIBM870,
 38   CSIBM871, CSIBM880, CSIBM891, CSIBM901, CSIBM902, CSIBM903, CSIBM904,
 39   CSIBM905, CSIBM918, CSIBM921, CSIBM922, CSIBM930, CSIBM932, CSIBM933,
 40   CSIBM935, CSIBM937, CSIBM939, CSIBM943, CSIBM1008, CSIBM1025, CSIBM1026,
 41   CSIBM1097, CSIBM1112, CSIBM1122, CSIBM1123, CSIBM1124, CSIBM1129, CSIBM1130,
 42   CSIBM1132, CSIBM1133, CSIBM1137, CSIBM1140, CSIBM1141, CSIBM1142, CSIBM1143,
 43   CSIBM1144, CSIBM1145, CSIBM1146, CSIBM1147, CSIBM1148, CSIBM1149, CSIBM1153,
 44   CSIBM1154, CSIBM1155, CSIBM1156, CSIBM1157, CSIBM1158, CSIBM1160, CSIBM1161,
 45   CSIBM1163, CSIBM1164, CSIBM1166, CSIBM1167, CSIBM1364, CSIBM1371, CSIBM1388,
 46   CSIBM1390, CSIBM1399, CSIBM4517, CSIBM4899, CSIBM4909, CSIBM4971, CSIBM5347,
 47   CSIBM9030, CSIBM9066, CSIBM9448, CSIBM12712, CSIBM16804, CSIBM11621162,
 48   CSISO4UNITEDKINGDOM, CSISO10SWEDISH, CSISO11SWEDISHFORNAMES,
 49   CSISO14JISC6220RO, CSISO15ITALIAN, CSISO16PORTUGESE, CSISO17SPANISH,
 50   CSISO18GREEK7OLD, CSISO19LATINGREEK, CSISO21GERMAN, CSISO25FRENCH,
 51   CSISO27LATINGREEK1, CSISO49INIS, CSISO50INIS8, CSISO51INISCYRILLIC,
 52   CSISO58GB1988, CSISO60DANISHNORWEGIAN, CSISO60NORWEGIAN1, CSISO61NORWEGIAN2,
 53   CSISO69FRENCH, CSISO84PORTUGUESE2, CSISO85SPANISH2, CSISO86HUNGARIAN,
 54   CSISO88GREEK7, CSISO89ASMO449, CSISO90, CSISO92JISC62991984B, CSISO99NAPLPS,
 55   CSISO103T618BIT, CSISO111ECMACYRILLIC, CSISO121CANADIAN1, CSISO122CANADIAN2,
 56   CSISO139CSN369103, CSISO141JUSIB1002, CSISO143IECP271, CSISO150,
 57   CSISO150GREEKCCITT, CSISO151CUBA, CSISO153GOST1976874, CSISO646DANISH,
 58   CSISO2022CN, CSISO2022JP, CSISO2022JP2, CSISO2022KR, CSISO2033,
 59   CSISO5427CYRILLIC, CSISO5427CYRILLIC1981, CSISO5428GREEK, CSISO10367BOX,
 60   CSISOLATIN1, CSISOLATIN2, CSISOLATIN3, CSISOLATIN4, CSISOLATIN5, CSISOLATIN6,
 61   CSISOLATINARABIC, CSISOLATINCYRILLIC, CSISOLATINGREEK, CSISOLATINHEBREW,
 62   CSKOI8R, CSKSC5636, CSMACINTOSH, CSNATSDANO, CSNATSSEFI, CSN_369103,
 63   CSPC8CODEPAGE437, CSPC775BALTIC, CSPC850MULTILINGUAL, CSPC862LATINHEBREW,
 64   CSPCP852, CSSHIFTJIS, CSUCS4, CSUNICODE, CSWINDOWS31J, CUBA, CWI-2, CWI,
 65   CYRILLIC, DE, DEC-MCS, DEC, DECMCS, DIN_66003, DK, DS2089, DS_2089, E13B,
 66   EBCDIC-AT-DE-A, EBCDIC-AT-DE, EBCDIC-BE, EBCDIC-BR, EBCDIC-CA-FR,
 67   EBCDIC-CP-AR1, EBCDIC-CP-AR2, EBCDIC-CP-BE, EBCDIC-CP-CA, EBCDIC-CP-CH,
 68   EBCDIC-CP-DK, EBCDIC-CP-ES, EBCDIC-CP-FI, EBCDIC-CP-FR, EBCDIC-CP-GB,
 69   EBCDIC-CP-GR, EBCDIC-CP-HE, EBCDIC-CP-IS, EBCDIC-CP-IT, EBCDIC-CP-NL,
 70   EBCDIC-CP-NO, EBCDIC-CP-ROECE, EBCDIC-CP-SE, EBCDIC-CP-TR, EBCDIC-CP-US,
 71   EBCDIC-CP-WT, EBCDIC-CP-YU, EBCDIC-CYRILLIC, EBCDIC-DK-NO-A, EBCDIC-DK-NO,
 72   EBCDIC-ES-A, EBCDIC-ES-S, EBCDIC-ES, EBCDIC-FI-SE-A, EBCDIC-FI-SE, EBCDIC-FR,
 73   EBCDIC-GREEK, EBCDIC-INT, EBCDIC-INT1, EBCDIC-IS-FRISS, EBCDIC-IT,
 74   EBCDIC-JP-E, EBCDIC-JP-KANA, EBCDIC-PT, EBCDIC-UK, EBCDIC-US, EBCDICATDE,
 75   EBCDICATDEA, EBCDICCAFR, EBCDICDKNO, EBCDICDKNOA, EBCDICES, EBCDICESA,
 76   EBCDICESS, EBCDICFISE, EBCDICFISEA, EBCDICFR, EBCDICISFRISS, EBCDICIT,
 77   EBCDICPT, EBCDICUK, EBCDICUS, ECMA-114, ECMA-118, ECMA-128, ECMA-CYRILLIC,
 78   ECMACYRILLIC, ELOT_928, ES, ES2, EUC-CN, EUC-JISX0213, EUC-JP-MS, EUC-JP,
 79   EUC-KR, EUC-TW, EUCCN, EUCJP-MS, EUCJP-OPEN, EUCJP-WIN, EUCJP, EUCKR, EUCTW,
 80   FI, FR, GB, GB2312, GB13000, GB18030, GBK, GB_1988-80, GB_198880,
 81   GEORGIAN-ACADEMY, GEORGIAN-PS, GOST_19768-74, GOST_19768, GOST_1976874,
 82   GREEK-CCITT, GREEK, GREEK7-OLD, GREEK7, GREEK7OLD, GREEK8, GREEKCCITT,
 83   HEBREW, HP-GREEK8, HP-ROMAN8, HP-ROMAN9, HP-THAI8, HP-TURKISH8, HPGREEK8,
 84   HPROMAN8, HPROMAN9, HPTHAI8, HPTURKISH8, HU, IBM-803, IBM-856, IBM-901,
 85   IBM-902, IBM-921, IBM-922, IBM-930, IBM-932, IBM-933, IBM-935, IBM-937,
 86   IBM-939, IBM-943, IBM-1008, IBM-1025, IBM-1046, IBM-1047, IBM-1097, IBM-1112,
 87   IBM-1122, IBM-1123, IBM-1124, IBM-1129, IBM-1130, IBM-1132, IBM-1133,
 88   IBM-1137, IBM-1140, IBM-1141, IBM-1142, IBM-1143, IBM-1144, IBM-1145,
 89   IBM-1146, IBM-1147, IBM-1148, IBM-1149, IBM-1153, IBM-1154, IBM-1155,
 90   IBM-1156, IBM-1157, IBM-1158, IBM-1160, IBM-1161, IBM-1162, IBM-1163,
 91   IBM-1164, IBM-1166, IBM-1167, IBM-1364, IBM-1371, IBM-1388, IBM-1390,
 92   IBM-1399, IBM-4517, IBM-4899, IBM-4909, IBM-4971, IBM-5347, IBM-9030,
 93   IBM-9066, IBM-9448, IBM-12712, IBM-16804, IBM037, IBM038, IBM256, IBM273,
 94   IBM274, IBM275, IBM277, IBM278, IBM280, IBM281, IBM284, IBM285, IBM290,
 95   IBM297, IBM367, IBM420, IBM423, IBM424, IBM437, IBM500, IBM775, IBM803,
 96   IBM813, IBM819, IBM848, IBM850, IBM851, IBM852, IBM855, IBM856, IBM857,
 97   IBM860, IBM861, IBM862, IBM863, IBM864, IBM865, IBM866, IBM866NAV, IBM868,
 98   IBM869, IBM870, IBM871, IBM874, IBM875, IBM880, IBM891, IBM901, IBM902,
 99   IBM903, IBM904, IBM905, IBM912, IBM915, IBM916, IBM918, IBM920, IBM921,
100   IBM922, IBM930, IBM932, IBM933, IBM935, IBM937, IBM939, IBM943, IBM1004,
101   IBM1008, IBM1025, IBM1026, IBM1046, IBM1047, IBM1089, IBM1097, IBM1112,
102   IBM1122, IBM1123, IBM1124, IBM1129, IBM1130, IBM1132, IBM1133, IBM1137,
103   IBM1140, IBM1141, IBM1142, IBM1143, IBM1144, IBM1145, IBM1146, IBM1147,
104   IBM1148, IBM1149, IBM1153, IBM1154, IBM1155, IBM1156, IBM1157, IBM1158,
105   IBM1160, IBM1161, IBM1162, IBM1163, IBM1164, IBM1166, IBM1167, IBM1364,
106   IBM1371, IBM1388, IBM1390, IBM1399, IBM4517, IBM4899, IBM4909, IBM4971,
107   IBM5347, IBM9030, IBM9066, IBM9448, IBM12712, IBM16804, IEC_P27-1, IEC_P271,
108   INIS-8, INIS-CYRILLIC, INIS, INIS8, INISCYRILLIC, ISIRI-3342, ISIRI3342,
109   ISO-2022-CN-EXT, ISO-2022-CN, ISO-2022-JP-2, ISO-2022-JP-3, ISO-2022-JP,
110   ISO-2022-KR, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5,
111   ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-9E, ISO-8859-10,
112   ISO-8859-11, ISO-8859-13, ISO-8859-14, ISO-8859-15, ISO-8859-16,
113   ISO-10646-UCS-2, ISO-10646, ISO-10646/UCS2, ISO-10646/UCS4, ISO-10646/UTF-8,
114   ISO-10646/UTF8, ISO-CELTIC, ISO-IR-4, ISO-IR-6, ISO-IR-8-1, ISO-IR-9-1,
115   ISO-IR-10, ISO-IR-11, ISO-IR-14, ISO-IR-15, ISO-IR-16, ISO-IR-17, ISO-IR-18,
116   ISO-IR-19, ISO-IR-21, ISO-IR-25, ISO-IR-27, ISO-IR-37, ISO-IR-49, ISO-IR-50,
117   ISO-IR-51, ISO-IR-54, ISO-IR-55, ISO-IR-57, ISO-IR-60, ISO-IR-61, ISO-IR-69,
118   ISO-IR-84, ISO-IR-85, ISO-IR-86, ISO-IR-88, ISO-IR-89, ISO-IR-90, ISO-IR-92,
119   ISO-IR-98, ISO-IR-99, ISO-IR-100, ISO-IR-101, ISO-IR-103, ISO-IR-109,
120   ISO-IR-110, ISO-IR-111, ISO-IR-121, ISO-IR-122, ISO-IR-126, ISO-IR-127,
121   ISO-IR-138, ISO-IR-139, ISO-IR-141, ISO-IR-143, ISO-IR-144, ISO-IR-148,
122   ISO-IR-150, ISO-IR-151, ISO-IR-153, ISO-IR-155, ISO-IR-156, ISO-IR-157,
123   ISO-IR-166, ISO-IR-179, ISO-IR-193, ISO-IR-197, ISO-IR-199, ISO-IR-203,
124   ISO-IR-209, ISO-IR-226, ISO/TR_11548-1, ISO646-CA, ISO646-CA2, ISO646-CN,
125   ISO646-CU, ISO646-DE, ISO646-DK, ISO646-ES, ISO646-ES2, ISO646-FI, ISO646-FR,
126   ISO646-FR1, ISO646-GB, ISO646-HU, ISO646-IT, ISO646-JP-OCR-B, ISO646-JP,
127   ISO646-KR, ISO646-NO, ISO646-NO2, ISO646-PT, ISO646-PT2, ISO646-SE,
128   ISO646-SE2, ISO646-US, ISO646-YU, ISO2022CN, ISO2022CNEXT, ISO2022JP,
129   ISO2022JP2, ISO2022KR, ISO6937, ISO8859-1, ISO8859-2, ISO8859-3, ISO8859-4,
130   ISO8859-5, ISO8859-6, ISO8859-7, ISO8859-8, ISO8859-9, ISO8859-9E,
131   ISO8859-10, ISO8859-11, ISO8859-13, ISO8859-14, ISO8859-15, ISO8859-16,
132   ISO11548-1, ISO88591, ISO88592, ISO88593, ISO88594, ISO88595, ISO88596,
133   ISO88597, ISO88598, ISO88599, ISO88599E, ISO885910, ISO885911, ISO885913,
134   ISO885914, ISO885915, ISO885916, ISO_646.IRV:1991, ISO_2033-1983, ISO_2033,
135   ISO_5427-EXT, ISO_5427, ISO_5427:1981, ISO_5427EXT, ISO_5428, ISO_5428:1980,
136   ISO_6937-2, ISO_6937-2:1983, ISO_6937, ISO_6937:1992, ISO_8859-1,
137   ISO_8859-1:1987, ISO_8859-2, ISO_8859-2:1987, ISO_8859-3, ISO_8859-3:1988,
138   ISO_8859-4, ISO_8859-4:1988, ISO_8859-5, ISO_8859-5:1988, ISO_8859-6,
139   ISO_8859-6:1987, ISO_8859-7, ISO_8859-7:1987, ISO_8859-7:2003, ISO_8859-8,
140   ISO_8859-8:1988, ISO_8859-9, ISO_8859-9:1989, ISO_8859-9E, ISO_8859-10,
141   ISO_8859-10:1992, ISO_8859-14, ISO_8859-14:1998, ISO_8859-15,
142   ISO_8859-15:1998, ISO_8859-16, ISO_8859-16:2001, ISO_9036, ISO_10367-BOX,
143   ISO_10367BOX, ISO_11548-1, ISO_69372, IT, JIS_C6220-1969-RO,
144   JIS_C6229-1984-B, JIS_C62201969RO, JIS_C62291984B, JOHAB, JP-OCR-B, JP, JS,
145   JUS_I.B1.002, KOI-7, KOI-8, KOI8-R, KOI8-RU, KOI8-T, KOI8-U, KOI8, KOI8R,
146   KOI8U, KSC5636, L1, L2, L3, L4, L5, L6, L7, L8, L10, LATIN-9, LATIN-GREEK-1,
147   LATIN-GREEK, LATIN1, LATIN2, LATIN3, LATIN4, LATIN5, LATIN6, LATIN7, LATIN8,
148   LATIN9, LATIN10, LATINGREEK, LATINGREEK1, MAC-CENTRALEUROPE, MAC-CYRILLIC,
149   MAC-IS, MAC-SAMI, MAC-UK, MAC, MACCYRILLIC, MACINTOSH, MACIS, MACUK,
150   MACUKRAINIAN, MIK, MS-ANSI, MS-ARAB, MS-CYRL, MS-EE, MS-GREEK, MS-HEBR,
151   MS-MAC-CYRILLIC, MS-TURK, MS932, MS936, MSCP949, MSCP1361, MSMACCYRILLIC,
152   MSZ_7795.3, MS_KANJI, NAPLPS, NATS-DANO, NATS-SEFI, NATSDANO, NATSSEFI,
153   NC_NC0010, NC_NC00-10, NC_NC00-10:81, NF_Z_62-010, NF_Z_62-010_(1973),
154   NF_Z_62-010_1973, NF_Z_62010, NF_Z_62010_1973, NO, NO2, NS_4551-1, NS_4551-2,
155   NS_45511, NS_45512, OS2LATIN1, OSF00010001, OSF00010002, OSF00010003,
156   OSF00010004, OSF00010005, OSF00010006, OSF00010007, OSF00010008, OSF00010009,
157   OSF0001000A, OSF00010020, OSF00010100, OSF00010101, OSF00010102, OSF00010104,
158   OSF00010105, OSF00010106, OSF00030010, OSF0004000A, OSF0005000A, OSF05010001,
159   OSF100201A4, OSF100201A8, OSF100201B5, OSF100201F4, OSF100203B5, OSF1002011C,
160   OSF1002011D, OSF1002035D, OSF1002035E, OSF1002035F, OSF1002036B, OSF1002037B,
161   OSF10010001, OSF10010004, OSF10010006, OSF10020025, OSF10020111, OSF10020115,
162   OSF10020116, OSF10020118, OSF10020122, OSF10020129, OSF10020352, OSF10020354,
163   OSF10020357, OSF10020359, OSF10020360, OSF10020364, OSF10020365, OSF10020366,
164   OSF10020367, OSF10020370, OSF10020387, OSF10020388, OSF10020396, OSF10020402,
165   OSF10020417, PT, PT2, PT154, R8, R9, RK1048, ROMAN8, ROMAN9, RUSCII, SE, SE2,
166   SEN_850200_B, SEN_850200_C, SHIFT-JIS, SHIFT_JIS, SHIFT_JISX0213, SJIS-OPEN,
167   SJIS-WIN, SJIS, SS636127, STRK1048-2002, ST_SEV_358-88, T.61-8BIT, T.61,
168   T.618BIT, TCVN-5712, TCVN, TCVN5712-1, TCVN5712-1:1993, THAI8, TIS-620,
169   TIS620-0, TIS620.2529-1, TIS620.2533-0, TIS620, TS-5881, TSCII, TURKISH8,
170   UCS-2, UCS-2BE, UCS-2LE, UCS-4, UCS-4BE, UCS-4LE, UCS2, UCS4, UHC, UJIS, UK,
171   UNICODE, UNICODEBIG, UNICODELITTLE, US-ASCII, US, UTF-7, UTF-8, UTF-16,
172   UTF-16BE, UTF-16LE, UTF-32, UTF-32BE, UTF-32LE, UTF7, UTF8, UTF16, UTF16BE,
173   UTF16LE, UTF32, UTF32BE, UTF32LE, VISCII, WCHAR_T, WIN-SAMI-2, WINBALTRIM,
174   WINDOWS-31J, WINDOWS-874, WINDOWS-936, WINDOWS-1250, WINDOWS-1251,
175   WINDOWS-1252, WINDOWS-1253, WINDOWS-1254, WINDOWS-1255, WINDOWS-1256,
176   WINDOWS-1257, WINDOWS-1258, WINSAMI2, WS2, YU
177 [root@slaver1 soft]# 

 


如果你需要在Linux中操作windows下的文件,那么你可能会经常遇到文件编码转换的问题。Windows中默认的文件格式是GBK(gb2312),而Linux一般都是UTF-8。下面介绍一下,在Linux中如何查看文件的编码及如何进行对文件进行编码转换。

一,查看文件编码:

在Linux中查看文件编码可以通过以下几种方式:

1)、在Vim中可以直接查看文件编码

:set fileencoding

即可显示文件编码格式,很香的命令。

1 [root@slaver1 soft]# vi aaa.txt 
2 [root@slaver1 soft]# 

[转] linux下查看文件编码及修改编码

Linux 如何查看文件编码格式及转换文件编码

Linux查看文件编码格式及文件编码转换

如何在 Linux 中将文件编码转换为 UTF-8

Linux解决乱码问题以及查看文件编码方式

linux文件编码转换及Windows上创建的文件转为Linux格式