介绍

有时候我们想要查看某个数据的内容,发现中文无法正确显示,这个时候就需要转换一下编码,Linux提供了一个很方便的工具iconv可以帮助实现。

用法

看一下帮助文档,很快可以理解,就是指定一下两个参数-f,-t

 $ iconv --help
Usage: iconv [OPTION...] [FILE...]
Convert encoding of given files from one encoding to another.

 Input/Output format specification:
  -f, --from-code=NAME       encoding of original text
  -t, --to-code=NAME         encoding for output

 Information:
  -l, --list                 list all known coded character sets

 Output control:
  -c                         omit invalid characters from output
  -o, --output=FILE          output file
  -s, --silent               suppress warnings
      --verbose              print progress information

  -?, --help                 Give this help list
      --usage                Give a short usage message
  -V, --version              Print program version

Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.

For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.

下面举个例子,我们要显示中文怎么办,

head data.txt | iconv -f gbk -t utf8
12-20 04:31