Locale
如何為 7z 指定字元編碼?
在檔案上做
7z x
給我'20 ª.1 ¯® '$'\302\212''¨à®¢®£à ¤áª ï ã«.rtf' IMG_6527.JPG ''$'\302\212''¨à®¢®£à ¤áª ï, ¨áâ.doc' IMG_6532.JPG ''$'\302\204''®¯ ᮣ« 襨¥(3).doc' IMG_6542.JPG ''$'\302\204\302\212\302\217''.doc' IMG_6543.JPG IMG_6526.JPG
顯然,某些文件的編碼方式不同,
7z
預設情況下不會轉換為 UTF-8。如何告訴7z
進行轉換?我為字元集找到的唯一選項:
-scc{UTF-8|WIN|DOS}
:為控制台輸入/輸出
-scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS|{id}}
設置字元集:為列表文件設置字元集
WIN
,DOS
,UTF-8
不工作。當試圖通過猜測字元集時7z -scsCP1251 l 26-08-2016_10-18-14.zip
7z 給出警告:
Unsupported charset: cp1251
unzip
這樣做對嗎(西里爾符號已轉換):'20 к.1 по Кировоградская ул.rtf' IMG_6532.JPG 'Доп соглашение(3).doc' 26-08-2016_10-18-14.zip IMG_6542.JPG 'Кировоградская, ист.doc' IMG_6526.JPG IMG_6543.JPG IMG_6527.JPG ДКП.doc
補充資料
- p7zip 版本:
15.14.1 (locale=ru_RU.UTF-8,Utf16=on,HugeFiles=on,64 bits,4 CPUs AMD Phenom(tm) II X4 960T Processor (100FA0),ASM)
- 歸檔開始的 hexdump (
od -tx1z -Ax
):000000 50 4b 03 04 14 00 00 00 00 00 81 54 1a 49 7e 35 >PK.........T.I~5< 000010 fa 34 00 ec 00 00 00 ec 00 00 07 00 17 00 84 8a >.4..............< 000020 8f 2e 64 6f 63 75 70 13 00 01 19 fd 45 54 d0 94 >..docup.....ET..< 000030 d0 9a d0 9f 2e 64 6f 63 00 00 00 00 d0 cf 11 e0 >.....doc........< 000040 a1 b1 1a e1 00 00 00 00 00 00 00 00 00 00 00 00 >................< 000050 00 00 00 00 3e 00 03 00 fe ff 09 00 06 00 00 00 >....>...........< 000060 00 00 00 00 00 00 00 00 01 00 00 00 71 00 00 00 >............q...< 000070 00 00 00 00 00 10 00 00 73 00 00 00 01 00 00 00 >........s.......< 000080 fe ff ff ff 00 00 00 00 70 00 00 00 ff ff ff ff >........p.......< 000090 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff >................< * 000230 ff ff ff ff ff ff ff ff ff ff ff ff ec a5 c1 00 >................< 000240 07 80 19 04 00 00 f0 12 bf 00 00 00 00 00 00 10 >................< 000250 00 00 00 00 00 08 00 00 72 7b 00 00 0e 00 62 6a >........r{....bj< 000260 62 6a 2a 16 2a 16 00 00 00 00 00 00 00 00 00 00 >bj*.*...........< 000270 00 00 00 00 00 00 00 00 19 04 16 00 34 8e 00 00 >............4...< 000280 48 7c 00 00 48 7c 00 00 4b 2c 00 00 00 00 00 00 >H|..H|..K,......< 000290 19 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 0002a0 00 00 00 00 00 00 00 00 ff ff 0f 00 00 00 00 00 >................< 0002b0 00 00 00 00 ff ff 0f 00 00 00 00 00 00 00 00 00 >................< 0002c0 ff ff 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 0002d0 00 00 00 00 b7 00 00 00 00 00 3e 0e 00 00 00 00 >..........>.....< 0002e0 00 00 3e 0e 00 00 a0 1b 00 00 00 00 00 00 a0 1b >..>.............< 0002f0 00 00 00 00 00 00 a0 1b 00 00 00 00 00 00 a0 1b >................< 000300 00 00 00 00 00 00 a0 1b 00 00 14 00 00 00 00 00 >................< 000310 00 00 00 00 00 00 ff ff ff ff 00 00 00 00 b4 1b >................< 000320 00 00 00 00 00 00 b4 1b 00 00 00 00 00 00 b4 1b >................< 000330 00 00 38 00 00 00 ec 1b 00 00 84 00 00 00 70 1c >..8...........p.< 000340 00 00 34 00 00 00 b4 1b 00 00 00 00 00 00 b8 28 >..4............(< 000350 00 00 e6 01 00 00 a4 1c 00 00 00 00 00 00 a4 1c >................< 000360 00 00 00 00 00 00 a4 1c 00 00 00 00 00 00 a4 1c >................< 000370 00 00 00 00 00 00 a4 1c 00 00 00 00 00 00 d8 1d >................< 000380 00 00 00 00 00 00 d8 1d 00 00 00 00 00 00 d8 1d >................< 000390 00 00 00 00 00 00 43 28 00 00 02 00 00 00 45 28 >......C(......E(< 0003a0 00 00 00 00 00 00 45 28 00 00 00 00 00 00 45 28 >......E(......E(< * 0003c0 00 00 00 00 00 00 45 28 00 00 00 00 00 00 9e 2a >......E(.......*< 0003d0 00 00 a2 02 00 00 40 2d 00 00 da 00 00 00 45 28 >......@-......E(< 0003e0 00 00 2d 00 00 00 00 00 00 00 00 00 00 00 00 00 >..-.............< 0003f0 00 00 00 00 00 00 a0 1b 00 00 00 00 00 00 d8 1d >................< 000400 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................< 000410 00 00 00 00 00 00 d8 1d 00 00 00 00 00 00 d8 1d >................< 000420
根據用於創建 zip 文件的編碼,您可以通過將語言環境臨時設置為“C”來防止不需要的翻譯:
LC_ALL=C 7z x $archive
(這有助於 IZArc 在 Win7 上使用您的兩個範例文件名創建的 zip。)
但是,對於問題中的存檔,“文件名”欄位包含“ДКП.doc”(
84 8a 8f 2e 64 6f 63
)的 CP1251 編碼。“額外”欄位使用 Info-zip 副檔名(參見Zip Specification v 6.3.4的第 4.6.9 節)來儲存 UTF-8 文件名。unzip
知道此標頭,並使用 UTF-8 名稱,忽略 CP1251 名稱。
7z
對這個“額外欄位”不做任何事情,只使用 CP1251 之一。根據目前的語言環境,它可能會使用該確切名稱(原始字節84 8a 8f
)創建文件,或者更糟的是,將它們視為 unicode 點以首先擴展為 UTF-8(c2 84 c2 8a c2 8f
)。一種選擇是使用外部實用程序來更改第
zip
一個:#!/bin/bash cp orig.zip renamed.zip index=0 zipinfo -1 orig.zip | while read name ; do ziptool renamed.zip rename $index "$name" index=$((index+1)) done
ziptool
來自libzip。zipinfo
與Info-ZIP 的 UnZip一起分發,因此您不妨使用unzip
.