How to view the character set of a file in Linux?

In Linux, you can use the file command to view the character set of a file. The specific command format is as follows:

file -i 文件名

To view the character set of the file example.txt, you can execute the following command:

file -i example.txt

After executing the command, detailed information about the file will be displayed, including the character set. The character set information will appear after “charset=”, for example:

example.txt: text/plain; charset=utf-8
bannerAds