macOS: How to show a file’s character encoding

macOS FAQ: How do I show a file’s character encoding?

On macOS you show a file’s character encoding using the -I option of the file command:

$ file -I file.txt
file.txt: text/plain; charset=utf-8

Here are two more examples that show the file command’s output, with and without the -I option:

$ file -I 00-intro.adoc
00-intro.adoc: text/plain; charset=utf-8

$ file 00-intro.adoc
00-intro.adoc: UTF-8 Unicode text, with very long lines