iconv命令可以用来在linux下转换文件的编码方式,在解决文件编码方式不兼容和网页抓取等方面比较有用。个人觉得用iconv来转换文件,不失为解决linux下zip压缩包乱码的一种方法。
-l 命令,显示当前已知的编码字符集合
panpan@Pan:~$ iconv -l
以下的列表包含所有已知的编码字符集,但这不代表所有的字符名称组合皆可用于
命令行的 "来源" 以及 "目的" 参数。一个编码字符集可以用几个不同的名称
来表示 (即 "别名")。
437, 500, 500V1, 850, 851, 852, 855, 856, 857, 860, 861, 862, 863, 864, 865,
866, 866NAV, 869, 874, 904, 1026, 1046, 1047, 8859_1, 8859_2, 8859_3, 8859_4,
8859_5, 8859_6, 8859_7, 8859_8, 8859_9, 10646-1:1993, 10646-1:1993/UCS4,
........
省略显示的其他部分。
选项
-f encoding :把字符从encoding编码开始转换。
-t encoding :把字符转换到encoding编码。
-l :列出已知的编码字符集合
-o file :指定输出文件
-c :忽略输出的非法字符
-s :禁止警告信息,但不是错误信息
--verbose :显示进度信息
-f和-t所能指定的合法字符在-l选项的命令里面都列出来了。
用法
将文件file1转码并输出到file2中
iconv file1 -f EUC-JP-MS -t UTF-8 -o file2获知文件编码方式的手段:
1,file命令的-i选项
file -i --mime-encoding filename
顺便列出file命令的其它选项,可用--help选项获得
Usage: file [OPTION...] [FILE...]
Determine type of FILEs.
--help display this help and exit
-v, --version output version information and exit
-m, --magic-file LIST use LIST as a colon-separated list of magic
number files
-z, --uncompress try to look inside compressed files
-Z, --uncompress-noreport only print the contents of compressed files
-b, --brief do not prepend filenames to output lines
-c, --checking-printout print the parsed form of the magic file, use in
conjunction with -m to debug a new magic file
before installing it
-e, --exclude TEST exclude TEST from the list of test to be
performed for file. Valid tests are:
apptype, ascii, cdf, compress, elf, encoding,
soft, tar, text, tokens
-f, --files-from FILE read the filenames to be examined from FILE
-F, --separator STRING use string as separator instead of `:'
-i, --mime output MIME type strings (--mime-type and
--mime-encoding)
--apple output the Apple CREATOR/TYPE
--extension output a slash-separated list of extensions
--mime-type output the MIME type
--mime-encoding output the MIME encoding
-k, --keep-going don't stop at the first match
-l, --list list magic strength
-L, --dereference follow symlinks (default if POSIXLY_CORRECT is set)
-h, --no-dereference don't follow symlinks (default if POSIXLY_CORRECT is not set) (default)
-n, --no-buffer do not buffer output
-N, --no-pad do not pad output
-0, --print0 terminate filenames with ASCII NUL
-p, --preserve-date preserve access times on files
-P, --parameter set file engine parameter limits
indir 15 recursion limit for indirection
name 30 use limit for name/use magic
elf_notes 256 max ELF notes processed
elf_phnum 128 max ELF prog sections processed
elf_shnum 32768 max ELF sections processed
-r, --raw don't translate unprintable chars to \ooo
-s, --special-files treat special (block/char devices) files as
ordinary ones
-C, --compile compile file specified by -m
-d, --debug print debugging messages
Report bugs to http://bugs.gw.com/