如何解决Ubuntu环境下解压中文显示乱码问题?Ubuntu解压中文乱码的多种解决办法
梦回刚读大学时折腾KDE。Linux固有诸多不可替代的优势,然而总能在编码、IO之类的小问题上搞点无伤大雅但需要手动解决的 尴尬 。
Windows压缩文件时,默认以系统编码中文来处理。由于zip文件中没有声明编码,所以 Linux上的unzip解压中文文件名会出现乱码,有三种方式解决问题:
unzip -O GBK filename.zip
也可以尝试将参数GBK替换为CP936、GB18030
有趣的是unzip的manual中并无这个选项的说明,unzip --help对这个参数有一行简单的说明。
在文件/etc/environment中加入两行
UNZIP="-O GBK"ZIPINFO="-O GBK"
安装:sudo apt-get install unar
使用:unar filename.zip
sudo apt install unar enca
转码脚本encoding.sh
#!/bin/bash#将文件编码更改为UTF-8#用法#1. 将文件命名encoding.sh#2. chmod +x encoding.sh#3. ./set_encoding.sh#4. 输入目录名称#5. 输入是否递归更改#$1表示是否要递归修改文件编码function change_file_encoing(){for file in $(ls -l|awk '{print $9}')doif [[ -d "$file" $1 = y ]];thencd $fileecho $filechange_file_encoing $1cd ..elif [[ -f "$file" ]];thenecho $fileenca -L zh_CN -x UTF-8 $filefi;done;#ecna -L zh_CN file UTF-8}read -p "please enter the dir path:" path #读取目录路径if [ ! -x "$path" ]; #判断目录是否存在且是否具有执行权限thenecho "dir path not exists"elseread -p "please enter if you want to recursive?y/n:" recur #是否递归fiif [ $recur == "y" ];thencd $pathchange_file_encoing "y" #递归修改文件编码elsecd $pathchange_file_encoing "n" #非递归修改fi
至此,可以批量用find,grep组合命令查找匹配中文。
安装p7zip-full
$sudo apt-get install p7zip-full
卸载unzip
$sudo apt-get remove unzip
再下载更新的p7zip-full包把原来的程序替换掉/usr/lib/p7zip/
PeaZip Portable 压缩解压缩软件 V9.4.0 绿色多国语言版
类型:压缩解压大小:5.54MB语言:简体中文时间:2023-08-21查看详情$sudo tar xzvf p7z-bin.tar.gz -C /usr/lib/p7zip
使用锁定p7zip、p7zip-rar和p7zip-full版本(防止更新后失效)
1) 安装新立得软件管理器 sudo apt-get install synaptic(如果已经安装可以略过)
2) 打开新立得软件包管理器,搜索p7zip
3) 在搜索出的结果中,选择p7zip、p7zip-rar和p7zip-full,再点击软件包 - 设置 - 锁定版本
如何解决Ubuntu环境下解压中文显示乱码问题?Ubuntu解压中文乱码的多种解决办法