且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

文件名和文件内容编码转换

更新时间:2022-09-10 08:28:01

1.文件名的编码转换
    初始安装Solaris系统时,LANG的值设置为C,然后lambo用ftp将MR上传到服务器上去之后解压,结果就发现先前提到的很多bug的图片名称就变成了乱码了.因此从网上找到了convmv的方法.经过测试,这种方法是有效的.
        convmv -f gb2312 -t utf8 -r --notest ./*
            -r表示递归转换,包括子文件夹
            --notest 表示直接转换,不是只去做转换测试而不做真正转换
    以下是sunfreeware上对convmv的介绍:
    Convmv converts filenames (not file content), directories, and even whole filesystems to a different encoding - installs in /usr/local. Dependencies: perl in /usr/local/bin or you can edit the convmv file in /usr/local/bin and change the first line to point to the perl you want to use.
    需要注意的是,convmv安装好之后,如果系统里面的perl是自带的而非后面单独安装的,则需要修改convmv文件的第一行中的#!后面的shell解释器为`which perl`的值.

2.文件内容的编码转换
    /bin/iconv -f fromencode -t toencode file
    要查看iconv支持的文件编码,可以用iconv -l来查看.



本文转自leipei博客园博客,原文链接:http://www.cnblogs.com/leipei2352/archive/2011/06/10/2077816.html,如需转载请自行联系原作者