linux
Linux 下 zip 文件解压乱码如何解决?
一、Linux 下 zip 文件解压乱码如何解决?
由于zip格式中并没有指定编码格式,Windows下生成的zip文件中的编码是GBK/GB2312等,因此,导致这些zip文件在Linux下解压时出现乱码问题,因为Linux下的默认编码是UTF8。
目前网上流传一种unzip -O cp936的方法,但一些unzip是没有-O这个选项的。
我使用的版本 unzip 6.0 debian modified 版本有这个选项
我发现另外两种解决方案可用。
python方案
此方案目前来看非常完美。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
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()
Windows 用户屏蔽两条 print 语句,Linux 用户不用屏蔽
7z方案
需要安装p7zip和convmv,在Fedora下的命令是
su -c 'yum install p7zip convmv'
在ubuntu下的安装命令是
sudo apt-get install p7zip convmv
安装完之后,就可以用7za和convmv两个命令完成解压缩任务。
LANG=C 7za x your-zip-file.zip
convmv -f GBK -t utf8 --notest -r .
第一条命令用于解压缩,而LANG=C表示以US-ASCII这样的编码输出文件名,如果没有这个语言设置,它同样会输出乱码,只不过是UTF8格式的乱码(convmv会忽略这样的乱码)。
第二条命令是将GBK编码的文件名转化为UTF8编码,-r表示递归访问目录,即对当前目录中所有文件进行转换。
二、php解压zip乱码
PHP解压ZIP乱码
当您在PHP中使用ZipArchive
类来解压缩文件时,有时候会遇到乱码的问题。这种问题可能是由于文件编码不一致导致的。下面将介绍一些解决这个问题的方法。
方法一:使用UTF-8编码
首先,确保您的ZIP文件采用UTF-8编码。在创建ZIP文件时,可以尝试将所有文件内容转换为UTF-8编码,这样在解压缩时就不容易出现乱码问题。
方法二:指定解压缩文件的编码格式
在使用ZipArchive
类解压文件时,可以尝试指定文件的编码格式。例如,您可以使用mb_convert_encoding
函数将解压出的文件内容从其他编码格式转换为UTF-8格式。
方法三:解决中文乱码问题
如果您在解压ZIP文件时遇到中文乱码问题,可以尝试在解压前将文件名从乱码转换为正确的编码格式。这可以通过使用iconv
函数或者手动指定编码来实现。
方法四:检查ZIP文件是否损坏
有时候乱码问题可能是由于ZIP文件本身损坏造成的。您可以通过使用工具检查ZIP文件的完整性,确保文件未损坏。
方法五:调试解压过程
对于无法确定原因的乱码问题,可以尝试在解压缩过程中添加一些调试信息,例如输出文件名、编码格式等,以便更好地定位问题所在。
结论
在使用PHP解压ZIP文件时遇到乱码问题并不少见,但通过以上方法可以有效解决这一问题。选择适合您情况的方法并结合调试过程,相信您能够顺利解决乱码问题。
三、linux 显示乱码?
1.查看当前系统语言
登陆linux系统打开操作终端之后,输入 echo $LANG可以查看当前使用的系统语言。如
2.查看安装的语言包
查看是否有中文语言包可以在终端输入 locale命令,如有zh cn 表示已经安装了中文语言。
3.可以通过网上下载安装中文语言包yum groupinstall chinese-support安装完后输入locale命令。
4.如何修改系统语言为中文
1 临时更换语言
如果只是临时更换linux系统的语言环境,可以通过输入设置 LANG=语言名称, 如中文是 LANG=zh_CN.UTF-8
2.修改系统默认语言
以上方法是通过修改设置系统默认的语言配置
如vi /etc/sysconfig/i18n (注意改好之后重启一下系统)。
四、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()
3.chmod +x uzip
4../uzip xxxx.zip
方法2,通过unzip行命令解压,指定字符集
unzip -O CP936 xxx.zip (用GBK, GB18030也可以)
有趣的是unzip的manual中并无这个选项的说明,unzip –help对这个参数有一行简单的说明。
方法3,在环境变量中,指定unzip参数,总是以指定的字符集显示和解压文件
/etc/environment中加入2行
UNZIP=”-O CP936″
ZIPINFO=”-O CP936″
方法4,采用java的jar命令解压zip包 JAR 解压
jar xvf file.name
五、linux怎么显示解压?
linux系统命令gzip和tar命令都可以显示解压。
六、360解压乱码怎么解决?
解决360压缩解压乱码
1.
点控制面板时钟与区域 点击打开“控制面板”,点击选择“时钟与区域”选项。
2.
点区域点管理点击选项 点击打开“区域”,点击“管理”,接着点击“更改系统区域设置”选项。
3.
选择中文点击确定 在弹出页面下拉选择“中文(简体,中国)”,然后点击“确定”。
4.
点击现在重新启动 最后点击“现在重新启动”即可。
七、zip解压乱码怎么解决?
zip文件的解压乱码可能是由于编码格式不匹配所致。常见的解决方法有:
1. 修改解压输出编码格式:在解压缩软件中,选择解压文件时,可以在选项中设置输出编码格式,尝试使用不同的编码格式,找到正确的编码格式。
2. 修改系统编码格式:在操作系统中,设置默认的编码格式,可以尝试修改为UTF-8或者GB2312等常见编码格式,然后重新解压缩文件。
3. 使用其他解压缩软件:使用其他解压缩软件,尝试解压缩文件,也许可以得到正确的结果。
4. 修改文件名:如果文件名中包含了特殊字符或者非常见字符,可以尝试修改文件名,然后重新解压缩文件。
总之,解压缩乱码问题的解决方法多种多样,可以根据具体情况尝试不同的解决方案,找到最适合自己的方法。
八、解压文件乱码怎么解决?
要解决双击能正常打开压缩包里的文件,而不是乱码的问题,可以先启动WinRAR软件,然后单击上面的菜单“选项”→“设置”→“查看器”选项卡,在“查看器类型”栏目里选中“关联程序”选项即可解决双击打开压缩文件为乱码的问题。
如果以上方法都无法解决问题,那么可能是压缩文件本身压缩的时候出现故障导致的,我们可以寻找下其他文件打开试试。
九、linux中乱码怎么解决?
1、宽带的费用不足。 目前,宽带基本上是后付费模式。 由于欠费时间过长,运营商直接关掉了宽带。 这种情况下,需要去支去缴清欠费才能恢复;
2、路由器的光信号接口有问题。 可能是连接口松动或连接口接触不良。 此时,需要拆下光信号的水晶连接口整理后重新插入;
3、路由器坏了。 这种事很少发生。 路由器损坏时,只有光信号不会闪烁红灯,所以请尝试重新启动路由器。
4、上联分光器故障,一般这种情况下周围的邻居也无法上网。 这个只能报警给运营商等员工上门维修了
十、linux 中如何解压文件?
打包压缩文件: 比如备份网站资料等, 防止传输过程中文件丢失, 打包下载
将打包 demo 为 demo.tar.gz tar zcvf demo.tar.gz demo
如果要解压 到当前位置 tar zxvf demo.tar.gz
但是如果要解压到其它位置 命令有点不一样的地方
如像要解压到另外的目录,如cc tar zxvf demo.tar.gz -C cc
或者 写全路径也行 tar zxvf demo.tar.gz -C /home/cc
这样就把这个包的内容释放到指定的那个目录中去了.
热点信息
-
在Python中,要查看函数的用法,可以使用以下方法: 1. 使用内置函数help():在Python交互式环境中,可以直接输入help(函数名)来获取函数的帮助文档。例如,...
-
一、java 连接数据库 在当今信息时代,Java 是一种广泛应用的编程语言,尤其在与数据库进行交互的过程中发挥着重要作用。无论是在企业级应用开发还是...
-
一、idea连接mysql数据库 php connect_error) { die("连接失败: " . $conn->connect_error);}echo "成功连接到MySQL数据库!";// 关闭连接$conn->close();?> 二、idea连接mysql数据库连...
-
要在Python中安装modbus-tk库,您可以按照以下步骤进行操作: 1. 确保您已经安装了Python解释器。您可以从Python官方网站(https://www.python.org)下载和安装最新版本...