In Debian you can also use: encguess:
$ encguess test.txt
test.txt US-ASCII
As it is a perl script, it can be installed on most systems, by installing perl or the script as standalone, in case perl has already been installed.
$ dpkg -S /usr/bin/encguess
perl: /usr/bin/encguess
Then there are several other implementations in various languages going under the name uchardet, that you can find some additional versions in the README here.
Then there is the classic file command. Perhaps with the most comprehensive magic file in existence, since it's been around as long as the C-language. You use it like this:
file -b --mime-encoding -P bytes=1024 xxxx.md
where:
-b: Do not prepend filenames to output lines (brief mode).
--mime-encoding: To output only the element of the mime type strings.
-P bytes=1024: Set the bytes parameter to read a maximum number of 1024 bytes.
(You can also use the encoding parameter.) *
* Caveat: Due to character-set byte-alignment, the results may depend on the number of bytes read. (Which is why Teocci wraps the command in a function to first read the total number of characters in the file, using wc. If you get a result of binary for a readable file, it is obviously wrong.)
Finally, there is also a native powershell function in this gist.
apropos encoding. It searches the titles and descriptions of all the manpages. When I do this on my machine, I see 3 tools that might help me, judging by their descriptions:chardet,chardet3,chardetect3. Then, by doingman chardetand reading the manpage tells me thatchardetis just the utility I need.us-ascii, but after add a line of Chinese comment, it becomesutf-8.filecan tell the encoding by reading the file content & guess.