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, with and without the file command’s -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