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?

  • 2
    You cannot tell the encoding of a file. You can only make a smart guess. You might mostly guess right, but sometimes guesses fail. file is an example of a program doing smart guesses. – Marco Sep 24 '13 at 21:17
  • 1
    @Marco: It is possible to verify whether it is valid UTF-8 or not, however. There are some encodings which can mistakenly pass as valid UTF-8, but it almost never happens with ISO-8859-𝒏 or Windows-125𝒏 encodings/charsets. – grawity Sep 24 '13 at 21:40

You can determine the file encoding with the following command:

file -bi filename
  • This answer should be accepted. The explanation for the -bi options is in the man file. – Jérôme Jan 13 '16 at 14:04
  • is it supposed to work on macos as well ? I get regular file on a file I though was utf8 – nicolas Apr 24 '16 at 15:49
  • 3
    @nicolas For MacOS you could try file -I filename (-I is a capital i). – Rik Apr 24 '16 at 16:07
  • @Rik I can confirm – nicolas Apr 24 '16 at 16:08
  • 1
    Does this read the whole file? – ctrl-alt-delor Mar 30 '18 at 15:17

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 I'm curious, is bad practice to cite the author in the reference? – Pablo Olmos de Aguilera C. Aug 28 '16 at 20:26
  • No. However, it is good practice to make the link say where it leads me. Assume I'm reading only the blue text. After the edit, I can tell why and when I should click that. Before, I could not. (It wasn't me who made the edit but I'm like 94% sure that this is what it was about.) – Hermann Döppes Dec 31 '18 at 0:00
  • Nice, and works nicely with find -type f -exec isutf8 {} +, because it also quotes the filename. (And with using find ... -exec ... + is also fast) – Tomasz Gandor Mar 22 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.