服务器技术

 首页 > 服务器技术 > Linux > linux与windows字符编码格式的自动调整 - Linux操作系

linux与windows字符编码格式的自动调整 - Linux操作系

分享到:
【字体:
导读:
          这几天频繁在windows和ubuntu下调试代码,字符编码格式不同老是造成很大的困扰,windows下的默认字符编码格式是GBK(gb2312)而在ubuntu下的是utf-8。前天光来回的保存编码格式就费了很大的...

 

这几天频繁在windows和ubuntu下调试代码,字符编码格式不同老是造成很大的困扰,windows下的默认字符编码格式是GBK(gb2312)而在ubuntu下的是utf-8。前天光来回的保存编码格式就费了很大的劲,今天google了下找到了个临时还算是不错的方法。

ubuntu下自带一个字符编码格式调整命令:iconv

 

ICONV(1)                       Debian GNU/Linux                       ICONV(1) 

 

NAME 

       iconv - Convert encoding of given files from one encoding to another 

 

SYNOPSIS 

       iconv -f encoding [-t encoding] [inputfile]... 

 

DESCRIPTION 

       The iconv program converts the encoding of characters in inputfile, or 

       from the standard input if no filename is specified, from one coded 

       character set to another. The result is written to standard output 

       unless otherwise specified by the --output option. 

 

       --from-code, -f encoding 

              Convert characters from encoding. 

 

       --to-code, -t encoding 

              Convert characters to encoding. If not specified the encoding 

              corresponding to the current locale is used. 

 

       --list, -l 

              List known coded character sets. 

 

       -c     Omit invalid characters from output. 

 

       --output, -o file 

              Specify output file (instead of stdout). 

 

       --silent, -s 

              Suppress warnings, but not errors. 

 

       --verbose 

              Print progress information. 

 

       --help, -? 

              Give help list. 

 

       --usage 

              Give a short usage message. 

 

       --version, -V 

              Print program version. 

 

ENCODINGS 

       The values permitted for --from-code and --to-code can be listed by the 

       iconv --list command, and all combinations of the listed values are 

       supported. Furthermore the following two suffixes are supported: 

 

       //TRANSLIT 

              When the string "//TRANSLIT" is appended to --to-code, 

              transliteration is activated.  This means that when a character 

              cannot be represented in the target character set, it can be 

              approximated through one or several similarly looking 

              characters. 

 

       //IGNORE 

              When the string "//IGNORE" is appended to --to-code, characters 

              that cannot be represented in the target character set will be 

              silently discarded. 

 

 

AUTHOR 

       iconv was written by Ulrich Drepper as part of the GNU C Library. 

 

       This man page was written by Joel Klecker , for the 

       Debian GNU/Linux system. 

 

 

3rd Berkeley Distribution            lenny                            ICONV(1) 

 

通过上面的介绍估计大家就可以很好的理解了。

iconv -f gb2312 -t utf-8 a.txt > b.txt;

 就可以将字符编码为gb2312的文件a.txt转换到编码格式为utf-8的b.txt文件。这样就可以在ubuntu下正常的查看了。希望可以帮到大家,自己也留底备用。

 

摘自timebomb的专栏

      上一篇:ubuntu server 时区修改 - Linux操作系统:Ubuntu_Cento 下一篇:linux 用户切换su 命令横杠的作用 - Linux操作系统:
    分享到:
    linux 用户切换su 命令横杠的作用 - Linu...
      挺凑巧的,最近老有同事问起这些问题,所以总结一下。   1. 首先用help理解su,sudo su,sudo 2. 其次理解"login shell" and "interactive shell".   "When Bash starts executes the commands in a variety of different scripts. (1) When started as an interactive login shell: Bash...
    ubuntu server 时区修改 - Linux操作系统...
      默认安装的时区为美国东部时区EST   root@ubuntu:/etc# date Mon Nov  7 14:46:55 EST 2011   修改为上海时区   root@ubuntu:/etc# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime   重新设置系统时间即可   http://www.2cto.com/os/201111/110314.html ...
    •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
    • 在这里……