33

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?

user219095
  • 65,551
Edward
  • 529

5 Answers5

30

You can determine the file encoding with the following command:

file -bi filename
Rik
  • 13,565
25

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

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


DavidPostill
  • 162,382
21

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.

phuclv
  • 30,396
  • 15
  • 136
  • 260
Tim
  • 311
  • 2
  • 4
1

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
mivk
  • 4,015
0

You can use the TextIntegrityInspector package to validate the integrity of your Joomla .ini files as UTF-8. Here's how you can do it:

Install TextIntegrityInspector:

pip install textIntegrityInspector

Use TextIntegrityInspector to validate files in the command line:

textIntegrityInspector path_to_your_ini_files --extensions ini

This will check all .ini files in the specified directory to ensure they are valid UTF-8.

Alternatively, use TextIntegrityInspector in a docker env:

docker run -it -v path_to_your_ini_files :/data text_integrity_inspector --extensions ini

You can add --language="fr" option to indicate only French characters are accepted ,