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?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityYou 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?
find -type f -exec isutf8 {} +
, because it also quotes the filename. (And with using find ... -exec ... +
is also fast)
Mar 22, 2019 at 13:28
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"
else
echo "NOT valid utf8: $FILE"
fi
file
is an example of a program doing smart guesses.