The iconv command is a common command used for file transcoding under linux. For students who use both the windows system and the linux system, file transcoding is also a frequently encountered operation.
1. Command format:
iconv [options...] [file...]
2. Command function:
Convert the encoding of the given file.
3. Common parameters:
Input/output format specification:
-f, --from-code=name raw text encoding
-t, --to-code=name Output encoding
information:
-l, --list List all known charsets
Output control:
- c ignore invalid characters from output
-o, --output=FILE output file
-s, --silent turn off warnings
--verbose print progress information
-?, --help give list of help for this system
--usage give brief Usage info for
-V, --version print program version number
4. Common examples:
Example 1: List currently supported character encodings:
Order
#iconv -l
Example: 2: file to utf-8 encoding
Order:
iconv abc.sh -o utf8 #Convert the file to utf8 format
Example 3: File GBK encoding to UTF-8 encoding
Order:
iconv test.txt -f GBK -t UTF-8 -o test2.txt
Example 4: Transcode the file file1, and output the converted file to fil2:
Order:
#iconv -f GBK -t UTF- 8 file1 -o file2 //No -o will output to standard output.
Example 5: Convert GB2312 encoding to UTF-8 encoding
Order:
iconv -f gb2312 -t utf-8 file1 > file2 #or iconv -f gb2312 -t utf-8 file1 -o file2