.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?
There is, use the
isutf8 command from the moreutils package.
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.
Yet another way is to use
recode, which will exit with an error if it tries to decode UTF-8 and encounters invalid characters.
if recode utf8/..UCS < "$FILE" >/dev/null 2>&1; then
echo "Valid utf8 : $FILE"
echo "NOT valid utf8: $FILE"