Howto find and detect the encoding of text files in Linux systems


How many times did you want to find and detect the encoding of a text files in Linux systems? or How many times did you try to watch a movie and it’s subtitles .srt  showed in unreadable shapes “characters” ?

All this because you are using a wrong encoding format for your text files. The solution for this is very simple Just knowing the text files encoding will end your problems.

In this mini post, I’ll show you different ways/options to find and detect the text files encoding in Linux systems using Linux commands available by default in all Linux distributions.

  • Option 1: Using file Command

The file command makes “best-guesses” about the encoding. Use the following command to determine what character encoding is used by a file :

$ file -bi [filename]
Option Description
-b, --brief Don’t print filename (brief mode)
-i, --mime Print filetype and encoding

Example 1 : Detect the encoding of the file “”

$ file -ib
text/plain; charset=iso-8859-1

As you see, “” file is encoded with iso-8859-1

Example 2 : Detect the encoding of the file “”

$ file -ib 
text/plain; charset=utf-8

Here’s the “” file is utf-8 encoded.

Finally, file command is perfect for telling you what exactly the encoding of a text file. You can use it to detect if your text file is encoded with UTF-8, WINDOWS-1256, ISO-8859-6, GEORGIAN-ACADEMY, etc…

  • Option 2: Using enca Command

Enca is an encoding guesser and converter. You can give it a language name and text that you presume is in that language (the supported languages are mostly East European languages), and it tries to guess the encoding.

$ enca [filename]

This may work on some files.

If You Appreciate What We Do Here On Mimastech, You Should Consider:

  1. Stay Connected to: Facebook | Twitter | Google+
  2. Support us via PayPal Donation
  3. Subscribe to our email newsletters.
  4. Tell other sysadmins / friends about Us - Share and Like our posts and services

We are thankful for your never ending support.

Leave a Reply

Your email address will not be published. Required fields are marked *