Linux: Convert File Encoding with iconv

By Xah Lee. Date: . Last updated: .

The GNU command line tool iconv does character encoding conversion.

# convert a file from utf-16 to utf-8
iconv -f utf-16 -t utf-8 file1.txt > file2.txt

iconv -l → show a list of encodings.

Here's the list of encodings:

  1. ANSI_X3.4-1968 ANSI_X3.4-1986 ASCII CP367 IBM367 ISO-IR-6 ISO646-US ISO_646.IRV:1991 US US-ASCII CSASCII
  2. UTF-8 UTF8
  3. UTF-8-MAC UTF8-MAC
  4. ISO-10646-UCS-2 UCS-2 CSUNICODE
  5. UCS-2BE UNICODE-1-1 UNICODEBIG CSUNICODE11
  6. UCS-2LE UNICODELITTLE
  7. ISO-10646-UCS-4 UCS-4 CSUCS4
  8. UCS-4BE
  9. UCS-4LE
  10. UTF-16
  11. UTF-16BE
  12. UTF-16LE
  13. UTF-32
  14. UTF-32BE
  15. UTF-32LE
  16. UNICODE-1-1-UTF-7 UTF-7 CSUNICODE11UTF7
  17. UCS-2-INTERNAL
  18. UCS-2-SWAPPED
  19. UCS-4-INTERNAL
  20. UCS-4-SWAPPED
  21. C99
  22. JAVA
  23. CP819 IBM819 ISO-8859-1 ISO-IR-100 ISO8859-1 ISO_8859-1 ISO_8859-1:1987 L1 LATIN1 CSISOLATIN1
  24. ISO-8859-2 ISO-IR-101 ISO8859-2 ISO_8859-2 ISO_8859-2:1987 L2 LATIN2 CSISOLATIN2
  25. ISO-8859-3 ISO-IR-109 ISO8859-3 ISO_8859-3 ISO_8859-3:1988 L3 LATIN3 CSISOLATIN3
  26. ISO-8859-4 ISO-IR-110 ISO8859-4 ISO_8859-4 ISO_8859-4:1988 L4 LATIN4 CSISOLATIN4
  27. CYRILLIC ISO-8859-5 ISO-IR-144 ISO8859-5 ISO_8859-5 ISO_8859-5:1988 CSISOLATINCYRILLIC
  28. ARABIC ASMO-708 ECMA-114 ISO-8859-6 ISO-IR-127 ISO8859-6 ISO_8859-6 ISO_8859-6:1987 CSISOLATINARABIC
  29. ECMA-118 ELOT_928 GREEK GREEK8 ISO-8859-7 ISO-IR-126 ISO8859-7 ISO_8859-7 ISO_8859-7:1987 ISO_8859-7:2003 CSISOLATINGREEK
  30. HEBREW ISO-8859-8 ISO-IR-138 ISO8859-8 ISO_8859-8 ISO_8859-8:1988 CSISOLATINHEBREW
  31. ISO-8859-9 ISO-IR-148 ISO8859-9 ISO_8859-9 ISO_8859-9:1989 L5 LATIN5 CSISOLATIN5
  32. ISO-8859-10 ISO-IR-157 ISO8859-10 ISO_8859-10 ISO_8859-10:1992 L6 LATIN6 CSISOLATIN6
  33. ISO-8859-11 ISO8859-11 ISO_8859-11
  34. ISO-8859-13 ISO-IR-179 ISO8859-13 ISO_8859-13 L7 LATIN7
  35. ISO-8859-14 ISO-CELTIC ISO-IR-199 ISO8859-14 ISO_8859-14 ISO_8859-14:1998 L8 LATIN8
  36. ISO-8859-15 ISO-IR-203 ISO8859-15 ISO_8859-15 ISO_8859-15:1998 LATIN-9
  37. ISO-8859-16 ISO-IR-226 ISO8859-16 ISO_8859-16 ISO_8859-16:2001 L10 LATIN10
  38. KOI8-R CSKOI8R
  39. KOI8-U
  40. KOI8-RU
  41. CP1250 MS-EE WINDOWS-1250
  42. CP1251 MS-CYRL WINDOWS-1251
  43. CP1252 MS-ANSI WINDOWS-1252
  44. CP1253 MS-GREEK WINDOWS-1253
  45. CP1254 MS-TURK WINDOWS-1254
  46. CP1255 MS-HEBR WINDOWS-1255
  47. CP1256 MS-ARAB WINDOWS-1256
  48. CP1257 WINBALTRIM WINDOWS-1257
  49. CP1258 WINDOWS-1258
  50. 850 CP850 IBM850 CSPC850MULTILINGUAL
  51. 862 CP862 IBM862 CSPC862LATINHEBREW
  52. 866 CP866 IBM866 CSIBM866
  53. MAC MACINTOSH MACROMAN CSMACINTOSH
  54. MACCENTRALEUROPE
  55. MACICELAND
  56. MACCROATIAN
  57. MACROMANIA
  58. MACCYRILLIC
  59. MACUKRAINE
  60. MACGREEK
  61. MACTURKISH
  62. MACHEBREW
  63. MACARABIC
  64. MACTHAI
  65. HP-ROMAN8 R8 ROMAN8 CSHPROMAN8
  66. NEXTSTEP
  67. ARMSCII-8
  68. GEORGIAN-ACADEMY
  69. GEORGIAN-PS
  70. KOI8-T
  71. CP154 CYRILLIC-ASIAN PT154 PTCP154 CSPTCP154
  72. MULELAO-1
  73. CP1133 IBM-CP1133
  74. ISO-IR-166 TIS-620 TIS620 TIS620-0 TIS620.2529-1 TIS620.2533-0 TIS620.2533-1
  75. CP874 WINDOWS-874
  76. VISCII VISCII1.1-1 CSVISCII
  77. TCVN TCVN-5712 TCVN5712-1 TCVN5712-1:1993
  78. ISO-IR-14 ISO646-JP JIS_C6220-1969-RO JP CSISO14JISC6220RO
  79. JISX0201-1976 JIS_X0201 X0201 CSHALFWIDTHKATAKANA
  80. ISO-IR-87 JIS0208 JIS_C6226-1983 JIS_X0208 JIS_X0208-1983 JIS_X0208-1990 X0208 CSISO87JISX0208
  81. ISO-IR-159 JIS_X0212 JIS_X0212-1990 JIS_X0212.1990-0 X0212 CSISO159JISX02121990
  82. CN GB_1988-80 ISO-IR-57 ISO646-CN CSISO57GB1988
  83. CHINESE GB_2312-80 ISO-IR-58 CSISO58GB231280
  84. CN-GB-ISOIR165 ISO-IR-165
  85. ISO-IR-149 KOREAN KSC_5601 KS_C_5601-1987 KS_C_5601-1989 CSKSC56011987
  86. EUC-JP EUCJP EXTENDED_UNIX_CODE_PACKED_FORMAT_FOR_JAPANESE CSEUCPKDFMTJAPANESE
  87. MS_KANJI SHIFT-JIS SHIFT_JIS SJIS CSSHIFTJIS
  88. CP932
  89. ISO-2022-JP CSISO2022JP
  90. ISO-2022-JP-1
  91. ISO-2022-JP-2 CSISO2022JP2
  92. CN-GB EUC-CN EUCCN GB2312 CSGB2312
  93. GBK
  94. CP936 MS936 WINDOWS-936
  95. GB18030
  96. ISO-2022-CN CSISO2022CN
  97. ISO-2022-CN-EXT
  98. HZ HZ-GB-2312
  99. EUC-TW EUCTW CSEUCTW
  100. BIG-5 BIG-FIVE BIG5 BIGFIVE CN-BIG5 CSBIG5
  101. CP950
  102. BIG5-HKSCS:1999
  103. BIG5-HKSCS:2001
  104. BIG5-HKSCS BIG5-HKSCS:2004 BIG5HKSCS
  105. EUC-KR EUCKR CSEUCKR
  106. CP949 UHC
  107. CP1361 JOHAB
  108. ISO-2022-KR CSISO2022KR
  109. CP856
  110. CP922
  111. CP943
  112. CP1046
  113. CP1124
  114. CP1129
  115. CP1161 IBM-1161 IBM1161 CSIBM1161
  116. CP1162 IBM-1162 IBM1162 CSIBM1162
  117. CP1163 IBM-1163 IBM1163 CSIBM1163
  118. DEC-KANJI
  119. DEC-HANYU
  120. 437 CP437 IBM437 CSPC8CODEPAGE437
  121. CP737
  122. CP775 IBM775 CSPC775BALTIC
  123. 852 CP852 IBM852 CSPCP852
  124. CP853
  125. 855 CP855 IBM855 CSIBM855
  126. 857 CP857 IBM857 CSIBM857
  127. CP858
  128. 860 CP860 IBM860 CSIBM860
  129. 861 CP-IS CP861 IBM861 CSIBM861
  130. 863 CP863 IBM863 CSIBM863
  131. CP864 IBM864 CSIBM864
  132. 865 CP865 IBM865 CSIBM865
  133. 869 CP-GR CP869 IBM869 CSIBM869
  134. CP1125
  135. EUC-JISX0213
  136. SHIFT_JISX0213
  137. ISO-2022-JP-3
  138. BIG5-2003
  139. ISO-IR-230 TDS565
  140. ATARI ATARIST
  141. RISCOS-LATIN1

See also: Emacs File Encoding FAQ

File Encoding

  1. Unicode Basics: Character Set, Encoding, UTF-8, Codepoint
  2. HTML: Character Sets and Encoding
  3. Unicode in Function Names and Operator Symbol
  4. Python: Unicode Tutorial 🐍
  5. Python: Convert File Encoding
  6. Python: Convert File Encoding for All Files in a Dir
  7. Perl: Unicode Tutorial 🐪
  8. Perl: Convert File Encoding
  9. Ruby: Unicode Tutorial 💎
  10. Java: Convert File Encoding
  11. Linux: Convert File Encoding with iconv

If you have a question, put $5 at patreon and message me.