欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何解決Ubuntu環(huán)境下解壓中文顯示亂碼問題? Ubuntu解壓中文亂碼的多種解決辦法

  發(fā)布時間:2024-01-09 15:20:23   作者:佚名   我要評論
在Ubuntu下解壓Windows下壓縮文件時,會出現(xiàn)解壓出的帶中文文件名的文件名亂碼,這大概率是因為buntu和Windows默認的編碼不同,當然也有其他原因,詳細請看下文介紹

夢回剛讀大學時折騰KDE。Linux固有諸多不可替代的優(yōu)勢,然而總能在編碼、IO之類的小問題上搞點無傷大雅但需要手動解決的“尷尬”。

Windows壓縮文件時,默認以系統(tǒng)編碼中文來處理。由于zip文件中沒有聲明編碼,所以 Linux上的unzip解壓中文文件名會出現(xiàn)亂碼,有三種方式解決問題:

通過unzip命令解壓,指定字符集參數(shù)

unzip -O GBK filename.zip

也可以嘗試將參數(shù)GBK替換為CP936、GB18030

有趣的是unzip的manual中并無這個選項的說明,unzip --help對這個參數(shù)有一行簡單的說明。

配置環(huán)境變量,總以指定的字符集處理文件

在文件/etc/environment中加入兩行

UNZIP="-O GBK"ZIPINFO="-O GBK"

使用The Unarchiver項目提供的lsar/unar工具。

安裝:sudo apt-get install unar

使用:unar filename.zip

解壓用unar工具,轉(zhuǎn)碼用enca。

sudo apt install unar enca

轉(zhuǎn)碼腳本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}')
	do
		if [[ -d "$file" && $1 = y ]];then
			cd $file
			echo $file
			change_file_encoing $1
			cd ..
		elif [[ -f "$file" ]];then
			echo $file
			enca -L zh_CN -x UTF-8 $file
		fi;
	done;
	#ecna -L zh_CN file UTF-8
}
read -p "please enter the dir path:" path #讀取目錄路徑
if [ ! -x "$path" ]; #判斷目錄是否存在且是否具有執(zhí)行權限
then
	echo "dir path not exists"
else
	read -p "please enter if you want to recursive?y/n:" recur #是否遞歸
fi
if [ $recur == "y" ];
then
	cd $path
	change_file_encoing "y" #遞歸修改文件編碼
else
	cd $path
	change_file_encoing "n" #非遞歸修改
fi

至此,可以批量用find,grep組合命令查找匹配中文。

使用p7zip解壓

安裝p7zip-full

$sudo apt-get install p7zip-full

卸載unzip

$sudo apt-get remove unzip

再下載更新的p7zip-full包把原來的程序替換掉/usr/lib/p7zip/

$sudo tar xzvf p7z-bin.tar.gz -C /usr/lib/p7zip

使用鎖定p7zip、p7zip-rar和p7zip-full版本(防止更新后失效)

1) 安裝新立得軟件管理器 sudo apt-get install synaptic(如果已經(jīng)安裝可以略過)

2) 打開新立得軟件包管理器,搜索p7zip

3) 在搜索出的結(jié)果中,選擇p7zip、p7zip-rar和p7zip-full,再點擊軟件包 -> 設置 -> 鎖定版本

相關文章

最新評論