Linux桌面系统解压Windows用户发来的zip压缩包乱码

现象

Linux桌面用户大多数都遇到这个问题,对Windows桌面用户发来的zip压缩包,双击打开或者解压,发现中文文件名和路径都是乱码。
image
通过命令行unzip解压也会得到一样的结果:

  12月 unzip xxx2022年12月居家办公情况表集合.zip 
Archive:  xxx2022年12月居家办公情况表集合.zip
  inflating: ░╜╘╦2022─ъ12╘┬╛╙╝╥░ь╣л╟щ┐Ў▒э╝п║╧/░╜╘╦2022-12-1.doc  
  inflating: ░╜╘╦2022─ъ12╘┬╛╙╝╥░ь╣л╟щ┐Ў▒э╝п║╧/░╜╘╦2022-12-15.doc  
  inflating: ░╜╘╦2022─ъ12╘┬╛╙╝╥░ь╣л╟щ┐Ў▒э╝п║╧/░╜╘╦2022-12-16.doc  
  inflating: ░╜╘╦2022─ъ12╘┬╛╙╝╥░ь╣л╟щ┐Ў▒э╝п║╧/░╜╘╦2022-12-2.doc  
  inflating: ░╜╘╦2022─ъ12╘┬╛╙╝╥░ь╣л╟щ┐Ў▒э╝п║╧/░╜╘╦2022-12-5.doc  

分析

实际上这个是zip这种压缩方式,并没有指定压缩的编码格式。而Windows下生成的zip文件中的编码是GBK/GB2312等,Linux默认编码格式是utf8.

➜  12月 echo $LANG      
zh_CN.UTF-8

这个时候可以用lsar查看一下压缩包内容:

➜  12月 lsar xxx2022年12月居家办公情况表集合.zip 
xxx2022年12月居家办公情况表集合.zip: Zip
xxx2022年12月居家办公情况表集合/xxx2022-12-1.doc
xxx2022年12月居家办公情况表集合/xxx2022-12-15.doc
xxx2022年12月居家办公情况表集合/xxx2022-12-16.doc
xxx2022年12月居家办公情况表集合/xxx2022-12-2.doc
xxx2022年12月居家办公情况表集合/xxx2022-12-5.doc
xxx2022年12月居家办公情况表集合/

还有更详细的参数:

  12月 lsar -L xxx2022年12月居家办公情况表集合.zip
xxx2022年12月居家办公情况表集合.zip: Zip
xxx2022年12月居家办公情况表集合/xxx2022-12-1.doc: 
  Name:                 xxx2022年12月居家办公情况表集合/xxx2022-12-1.doc
  Size:                 31.2 KB (31,232 bytes)
  Compressed size:      16.9 KB (16,890 bytes)
  Compression type:     Deflate
  Last modified:        2022-12-16 18:09:52 +0800
  DOS file attributes:  A----- (0x20)
  Index in file:        0
  Start of data:        80
  Length of data:       16890
  ZipCRC32:             0xba90c296
  ZipCompressionMethod: 8
  ZipExtractVersion:    20
  ZipFileAttributes:    32
  ZipFlags:             0
  ZipLocalDate:         1435537722
  ZipOS:                0
  ZipOSName:            MS-DOS
  ......................................................................

从最后一句 ZipOSName: MS-DOS看得出来,这个zip压缩文件来自Windows系统。
而Linux系统本身压缩的zip文件,最后一个属性是ZipOSName: Unix

解决

在Linux系统下解压Windows用户打包的zip文件,有两个方式:

一、unzip

unzip解压并指定编码类型 -O,可用的参数值gbk gb2312 gb18030 cp930

➜  12月 unzip -O gbk xxx2022年12月居家办公情况表集合.zip
Archive:  xxx2022年12月居家办公情况表集合.zip
  inflating: xxx2022年12月居家办公情况表集合/xxx2022-12-1.doc  
  inflating: xxx2022年12月居家办公情况表集合/xxx2022-12-15.doc  
  inflating: xxx2022年12月居家办公情况表集合/xxx2022-12-16.doc  
  inflating: xxx2022年12月居家办公情况表集合/xxx2022-12-2.doc  
  inflating: xxx2022年12月居家办公情况表集合/xxx2022-12-5.doc 

二、unar

➜  12月 unar xxx2022年12月居家办公情况表集合.zip 
xxx2022年12月居家办公情况表集合.zip: Zip
  xxx2022年12月居家办公情况表集合/xxx2022-12-1.doc  (31232 B)... OK.
  xxx2022年12月居家办公情况表集合/xxx2022-12-15.doc  (31232 B)... OK.
  xxx2022年12月居家办公情况表集合/xxx2022-12-16.doc  (31232 B)... OK.
  xxx2022年12月居家办公情况表集合/xxx2022-12-2.doc  (31232 B)... OK.
  xxx2022年12月居家办公情况表集合/xxx2022-12-5.doc  (31232 B)... OK.
  xxx2022年12月居家办公情况表集合/  (dir)... OK.
Successfully extracted to "./xxx2022年12月居家办公情况表集合".

image

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章