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]
||Don’t print filename (brief mode)|
||Print filetype and encoding|
Example 1 : Detect the encoding of the file “storks.srt”
$ file -ib storks.srt text/plain; charset=iso-8859-1
As you see, “storks.srt” file is encoded with
Example 2 : Detect the encoding of the file “The.Girl.on.the.Train.2016.1080p.WEB-DL.DD5.1.H264-FGT.srt”
$ file -ib The.Girl.on.the.Train.2016.1080p.WEB-DL.DD5.1.H264-FGT.srt text/plain; charset=utf-8
Here’s the “The.Girl.on.the.Train.2016.1080p.WEB-DL.DD5.1.H264-FGT.srt” file is
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:
- Stay Connected to: Facebook | Twitter | Google+
- Support us via PayPal Donation
- Subscribe to our email newsletters.
- Tell other sysadmins / friends about Us - Share and Like our posts and services
We are thankful for your never ending support.