HowTo : Determine and Change File Character Encoding
From the following article you'll learn how to detect a file's encoding from the command line in Linux.
You will also find the best solution to convert text files between different character sets.
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 character sets.
Detect a File's Encoding
Use the following command to determine what character encoding is used by a file :
|-b, --brief||Don't print filename (brief mode)|
|-i, --mime||Print filetype and encoding|
Example : Detect the encoding of the file
Change a File's Encoding
Use the following command to convert the encoding of a file :
|-f, --from-code||Convert characters from encoding|
|-t, --to-code||Convert characters to encoding|
|-o, --output||Specify output file (instead of stdout)|
Example : Convert a file's encoding from CP1251 (Windows-1251, Cyrillic) to UTF-8
Example : Convert a file's encoding from ISO-8859-1 to UTF-8 and save it to
Example : Convert a file's encoding from ASCII to UTF-8
Example : Convert a file's encoding from UTF-8 to ASCII
|-c||Omit invalid characters from output|
[BONUS] Change a string's encoding from CP1251 (Windows-1251, Cyrillic) to UTF-8
List All Encodings
List all the coded character sets known :
|-l, --list||List known coded character sets|