

使用gbkunzip解决linux下zip文件解压乱码问题
source link: https://www.lujun9972.win/blog/2017/06/04/%E4%BD%BF%E7%94%A8gbkunzip%E8%A7%A3%E5%86%B3linux%E4%B8%8Bzip%E6%96%87%E4%BB%B6%E8%A7%A3%E5%8E%8B%E4%B9%B1%E7%A0%81%E9%97%AE%E9%A2%98/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用gbkunzip解决linux下zip文件解压乱码问题
由于Windows下的文件名为GBK编码,而linux一般为UTF-8,因此当解压在Windows上生成的zip文件后,会发现解压出来的文件都是乱码的.
网上有个解决方法是使用 unzip
的 -O
选项来指定编码格式,然而不知道为何,我在archlinux下的unzip并没有这个选项.
好在找到了一个 gbkunzip
脚本,可以解决这个问题.
在archlinux上,可以通过yaourt来安装 gbkunzip
yaourt -S gbkunzip
安装后,直接执行 gbkunzip zip文件
就行了.
gbkunzip实际上就是一段python代码,它其实就是对 gbzip
module中 ZipFile
类的一个封装.
cat $(whereis gbkunzip |awk '{print $2}')
#!/usr/bin/env python3 # fileencoding=utf-8 ''' 解压 zip 文件,其中的文件名是 GB18030 编码,但系统是 Unicode 编码 ''' import sys import os from gbzip import ZipFile from getpass import getpass def main(): try: z = ZipFile(sys.argv[1]) while True: try: z.extractall() except RuntimeError: # encrypted zipfile passwd = getpass('Enter correct password: ').encode() z.setpassword(passwd) else: break print('Everything is ok.') except IndexError: sys.exit('give me exactly one zipfile to extract.') if __name__ == '__main__': main()
Recommend
-
16
在日常开发中,针对数据导出,我们可以导出Excel格式,但是如果是针对大数据量的导出,直接导出为Excel格式可能需要占用...
-
7
csv 文件打开乱码,有哪些方法可以解决? Excel 在读取 csv 的时候是通过读取文件头上的 bom 来识别编码的,这导致如果我们生成 csv 文件的平台输出无 bom 头编...
-
7
excel打开csv文件乱码的解决方法 浏览:883次 出处信息 通过程序导出生成txt...
-
14
Mac下使用SecureCRT时中文乱码问题解决 ...
-
6
tomcat服务器上utf8编码的文件乱码解决方法 发布于 2022年2月23日| 更新于 2022年2月23日| 分类于 清学小记| 标签
-
12
解决ubuntu下zip文件解压后中文乱码问题 | 幻悠尘的小窝幻悠尘的小窝The quieter you become,the more you are able to hear.解决ubuntu下zip文件解压后中文乱...
-
5
-
9
解决使用 mPDF 导出 PDF 时中文及符号乱码问题 后端开发 · 实用资源 / ...
-
5
IE 11下载文件中文乱码解决(go/php) rariki · 2016-04-07 21:00:06 · 11192 次点击 · 预计阅读时间 2 分钟 · 大约8小时之前 开始浏览 ...
-
5
我的系统是ubuntu 10.04 ,编码是zh_CN.UTF-8。 我从网络上下载的绝大部分zip包,解压后,连带目录和文件都是乱码。在终端尝试更换LANG,LANGUAGE等环境变量,还是不能直接解决问题。 而且用unzip解压后,无论你怎么设置convmv命令的编码...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK