
List all the known charsets in your Linux system: $ iconv -l Option You have copied some file from Windows to Linux, but when you open it in Linux, you see “Êàêèå-òî êðàêîçÿáðû” – WTF!?ĭon’t panic – such strings can be easily converted from CP1251 (Windows-1251, Cyrillic) charset to UTF-8 with: $ echo "Êàêèå-òî êðàêîçÿáðû" | iconv -t latin1 | iconv -f cp1251 -t utf-8 This concerns in particular Windows machines with Cyrillic.

Very common situation for ones who work inside the both Windows and Linux machines. You can lose characters: Note that if you use the iconv with the -c option, nonconvertible characters will be lost. $ iconv -c -f utf-8 -t ascii -o out.txt in.txt Option Illegal input sequence at position: As UTF-8 can contain characters that can’t be encoded with ASCII, the iconv will generate the error message “ illegal input sequence at position” unless you tell it to strip all non-ASCII characters using the -c option. Use the following command to change the encoding of a file: $ iconv -f -t -o OptionĬhange a file’s encoding from CP1251 (Windows-1251, Cyrillic) charset to UTF-8: $ iconv -f cp1251 -t utf-8 in.txtĬhange a file’s encoding from ISO-8859-1 charset to and save it to out.txt: $ iconv -f iso-8859-1 -t utf-8 -o out.txt in.txtĬhange a file’s encoding from ASCII to UTF-8: $ iconv -f utf-8 -t ascii -o out.txt in.txtĬhange a file’s encoding from UTF-8 charset to ASCII: Text/plain charset=utf-8 Change a File’s Encoding Use the following command to check what encoding is used in a file: $ file -bi OptionĬheck the encoding of the file in.txt: $ file -bi in.txt I’ll also show the most common examples of how to convert a file’s encoding between CP1251 (Windows-1251, Cyrillic), UTF-8, ISO-8859-1 and ASCII charsets.Ĭool Tip: Want see your native language in the Linux terminal? Simply change locale! Read more → Check a File’s Encoding


You will also find the best solution to convert text files between different charsets. The Linux administrators that work with web hosting know how is it important to keep correct character encoding of the html documents.įrom the following article you’ll learn how to check a file’s encoding from the command-line in Linux.
