Linux系统unzip解压后中文名乱码解决方法

/ Linux / 没有评论 / 1857浏览

Linux系统unzip解压后中文名乱码解决方法

中文名在linux中必须是乱码的哦这个没话说了,当然如果有配置好的估计是可以解决,下面小编整理了一些解决unzip解压后中文名乱码问题。

一、利用pyton来处理

  1. vi uzip文件
  2. 复制以下内容(Python)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# uzip.py

import os
import sys
import zipfile

print "Processing File " + sys.argv[1]

file=zipfile.ZipFile(sys.argv[1],"r");
for name in file.namelist():
    utf8name=name.decode('gbk')
    print "Extracting " + utf8name
    pathname = os.path.dirname(utf8name)
    if not os.path.exists(pathname) and pathname!= "":
        os.makedirs(pathname)
    data = file.read(name)
    if not os.path.exists(utf8name):
        fo = open(utf8name, "w")
        fo.write(data)
        fo.close
file.close()1234567891011121314151617181920212223
  1. chmod +x uzip
  2. ./uzip xxxx.zip

二、通过unzip行命令解压,指定字符集

unzip -O CP936 xxx.zip (用GBK, GB18030也可以)1

有趣的是unzip的manual中并无这个选项的说明,unzip –help对这个参数有一行简单的说明。

三、在环境变量中,指定unzip参数,总是以指定的字符集显示和解压文件

/etc/environment中加入2行

UNZIP=”-O CP936″
ZIPINFO=”-O CP936″

四、java的jar命令解压zip包 JAR 解压

jar xvf file.name