Is there a Linux command to find out if a file is UTF-8?

The Joomla .ini files require to be saved as UTF-8.

After editing I'm not sure if the files are UTF-8 or not.

Is there a Linux command like file or a few commands that would tell if a file is indeed UTF-8 or not?


You can determine the file encoding with the following command:

file -bi filename

There is, use the isutf8 command from the moreutils package.

Source: How can you tell if a file is UTF-8 encoded or not?



Do not use the file command. It does not inspect the whole file, and it basically guesses. It sometimes gives incorrect answers.

You can verify if a file happens to pass UTF-8 encoding like this:

$ iconv -f utf8 <filename> -t utf8 -o /dev/null

A return code of zero means it passes UTF8. A non-zero return code means it is not valid UTF8.

It is not possible to know if a file was necessarily exported using any particular encoding scheme, as some encoding schemes overlap. To do that would require metadata to be embedded in the file, and even then you would be placing trust in whoever generated that file, rather than validating it yourself... and you should always validate it yourself.