Linux编码转换相关

来自三线的随记

command or tools

  • vim -> set fileencoding
  • convmv -> 转换文件名编码
  • iconv -> 单文件转换
  • enca

enca的相关补充

enca --help

Usage:  enca [-L LANGUAGE] [OPTION]... [FILE]...

        enconv [-L LANGUAGE] [OPTION]... [FILE]...

Detect encoding of text files and convert them if required.

但是实际上enca并不是单纯的enconv别名关系的样子

root@miniServer:/var/www# enca -L zh_CN News.csv

Universal transformation format 8 bits; UTF-8

root@miniServer:/var/www# enconv -L zh_CN News.csv

enconv: Cannot detect native charset for locale zh.

You have to use the `-x' option or the DEFAULT_CHARSET environment variable to set the target encoding manually.

iconv

echo xxxx | iconv -f gbk -t utf8


convert 7-bit ASCII representations to UTF-8 Unicode

16进制的unicode编码转汉字

need packge: uni2ascii

root@miniServer:~/myfile/temp# ls -l | awk '{gsub("#U","\\u",$0);print $0}' | ascii2uni -a U -q
total 1236020
drwxr-xr-x   4 root root       4096 Sep 11 00:08 内网渗透
drwxr-xr-x   7 root root       4096 Sep 11 00:08 域渗透
drwxr-xr-x  12 root root       4096 Sep 11 00:08 安全工具
drwxr-xr-x  15 root root       4096 Sep 11 00:08 安全技术
drwxr-xr-x   3 root root       4096 Sep 11 00:08 工控安全
drwxr-xr-x   5 root root       4096 Sep 11 00:08 系统安全
drwxr-xr-x  15 root root       4096 Sep 11 00:08 IOT安全
drwxr-xr-x 228 root root      12288 Sep 19 00:55 Web安全
-rw-r--r--   1 root root 1265636581 Sep 19 14:59 zero.zip

root@miniServer:~/myfile/temp# ls -l
total 1236020
drwxr-xr-x   4 root root       4096 Sep 11 00:08 '#U5185#U7f51#U6e17#U900f'
drwxr-xr-x   7 root root       4096 Sep 11 00:08 '#U57df#U6e17#U900f'
drwxr-xr-x  12 root root       4096 Sep 11 00:08 '#U5b89#U5168#U5de5#U5177'
drwxr-xr-x  15 root root       4096 Sep 11 00:08 '#U5b89#U5168#U6280#U672f'
drwxr-xr-x   3 root root       4096 Sep 11 00:08 '#U5de5#U63a7#U5b89#U5168'
drwxr-xr-x   5 root root       4096 Sep 11 00:08 '#U7cfb#U7edf#U5b89#U5168'
drwxr-xr-x  15 root root       4096 Sep 11 00:08  IOT#U5b89#U5168
drwxr-xr-x 228 root root      12288 Sep 19 00:55  Web#U5b89#U5168
-rw-r--r--   1 root root 1265636581 Sep 19 14:59  zero.zip