How to change the character encoding of a file in Linux?
In Linux, the iconv command can be used to change the character set encoding of a file. Here is an example of using the iconv command to modify the character set encoding of a file:
- Check the current character encoding of the file.
file -i filename
- converts the encoding of text files.
iconv -f current_charset -t target_charset filename > output_filename
current_charset is the character encoding of the current file, target_charset is the character encoding of the target, filename is the name of the file to be converted, and output_filename is the name of the output file after conversion.
For example, to convert a file from UTF-8 encoding to GBK encoding, you can use the following command:
iconv -f UTF-8 -t GBK filename > output_filename
Please note that converting character encoding may result in changes or loss of text content, so make sure to back up the original file before proceeding with the conversion.