問題描述
在macOS上用unzip $ZIPFILE.zip
命令解壓文件,當ZIPFILE.zip
中的路徑/文件名含有中文且中文是GBK編碼時,會報類似下面的錯誤
checkdir error: cannot create ??+?
Illegal byte sequence
unable to process ??+?/08 ??µ?????+???ĵ?µ????⵿????
原因在於macOS的默認編碼是zh_CN.UTF-8
(可在terminal中使用locale
命令查看),unzip無法處理GBK編碼的中文。
解決方案是使用unar軟件指定編碼方式解壓。
解決方法
首先使用HomeBrew下載unar
brew install unar
然後使用unar的-e
參數指定GBK
編碼解壓
unar -e GBK $ZIPFILE.zip
說明
有時遇到unzip解壓編碼問題,未必原中文路徑是GBK編碼,需要結合實際問題分析。只是中文系統中GBK應用比較多,因此GBK引發的亂碼錯誤也是最多的。