Garbled file names after unzipping on a Mac
You unzip a file someone sent from Windows, and the names come out wrong:
ЏаЁўҐв.txtinstead ofПривет.txtR‚sum‚ caf‚.txtinstead ofRésumé café.txt- or
unzipin Terminal stops withIllegal byte sequence
The files themselves are fine. Only their names were read with the wrong alphabet, and you can get the right names back without installing anything.
Why it happens
A ZIP can store file names in two ways: in Unicode, with a flag that says so, or in whatever character set the computer that made it was using, with nothing recording which one. Many Windows apps, and older versions of Windows itself, use the second way, so a ZIP made on a Russian, Japanese, or French PC stores its names in that PC’s local character set (its “code page”).
A Mac has to guess. In our tests, Archive Utility guessed Japanese, Chinese,
and Korean names correctly, but not Russian or accented Western names like
Résumé. The unzip command doesn’t guess at all.
7z and RAR archives store names in Unicode, so this is almost always a ZIP problem.
Fix it with Terminal (built into macOS)
The tar command that comes with macOS can read a ZIP and tell it which
character set the names use. Pick the code page for the language the names
should be in:
| Names in | Code page |
|---|---|
| Russian, Ukrainian, other Cyrillic | CP866 |
| Western European (é, ü, ñ) | CP850 (or CP437) |
| Japanese | CP932 |
| Chinese (Simplified) | CP936 |
| Chinese (Traditional) | CP950 |
| Korean | CP949 |
First, list the names to check you picked the right one:
tar -tf ~/Downloads/file.zip --options zip:hdrcharset=CP866If they read correctly, extract into a new folder:
mkdir ~/Desktop/unzipped
tar -xf ~/Downloads/file.zip -C ~/Desktop/unzipped --options zip:hdrcharset=CP866If the names still look wrong, try another code page from the table. Western
names usually come out right with either CP850 or CP437.
You might see 7-Zip’s -mcp option suggested for this. On a Mac, 7-Zip’s
command-line version ignores it, so use tar.
Or use an app
The Unarchiver (free on the Mac App Store) detects the character set of ZIP file names and lets you choose one when it can’t tell.
Purrchiver doesn’t convert these names yet, so for a ZIP like this, use one of the options above.
The same thing in reverse
ZIPs made with the Finder’s Compress store names in Unicode but don’t mark
them as Unicode, so some Windows tools show the names of a ZIP from a Mac
garbled in the same way. 7-Zip marks them; with
Homebrew, brew install sevenzip, then
7zz a -tzip archive.zip folder. Or send a 7z, which always stores names in
Unicode.