zip and unzip Basics: Cross-Platform Archives on Linux

zip and unzip Basics: Cross-Platform Archives on Linux

What You'll Learn

Conclusion: Zip it up, unzip it open. Add content inspection and a fix for garbled filenames, and you're ready to swap archives with Windows users.

  • Use zip to compress files and directories into a .zip
  • Use unzip to extract a .zip (including ones made on Windows)
  • Inspect archive contents before extracting, safely
  • Fix garbled filenames in ZIPs that came from Windows

Who this is for: readers comfortable with basic file commands who need to exchange files with Windows.

Intro: A zip file from a Windows user

Conclusion: Windows uses ZIP by default. With zip / unzip on Linux, both sides can send compressed files to each other.

Lina: Linny-senpai, a Windows user sent me a file called report.zip. Can I open it on Linux?
Linny-senpai: Absolutely. That .zip is exactly what Windows creates when you right-click and "compress." On Linux you open it with unzip and create one with zip.
Lina: Wait, isn't that different from the tar we learned before?
Linny-senpai: Great question. tar (.tar.gz) is what Linux folks use among themselves. The strength of .zip is that Windows opens it natively. So remember: "talking to Windows? use zip."

1. What are zip / unzip, and how do they differ from tar?

Conclusion: zip both bundles and compresses in one step. Because Windows supports it natively, zip is the safe choice when the other side runs Windows.

Lina: I always hesitate between zip and tar.
Linny-senpai: Think of it roughly like this.
Format Best for Note
.zip Exchanging with Windows Windows opens it natively
.tar.gz Linux / Mac to each other Preserves permissions precisely

When in doubt: use zip for Windows, and tar.gz for Linux / Mac. That single rule is enough to start.

Lina: So I pick based on the other person's OS.
Linny-senpai: Exactly. One more detail: zip does "bundle" and "compress" in a single command, while tar only bundles and pairs with gzip to compress. Don't worry about that at first, though.

2. Install zip / unzip

Conclusion: Ubuntu may not ship zip / unzip by default. Install them once with sudo apt install zip unzip.

Lina: I tried to use it and got unzip: command not found...
Linny-senpai: Classic. Ubuntu sometimes doesn't include it out of the box. Install it once and you're set.
$ sudo apt install zip unzip
Lina: I install both zip and unzip together?
Linny-senpai: Yes. zip (the maker) and unzip (the opener) are separate packages, so installing both keeps you covered. To check whether they're installed, use which.
$ which zip unzip
/usr/bin/zip
/usr/bin/unzip

3. Compress with zip

Conclusion: For files, zip name.zip file; for directories, add -r as in zip -r name.zip dir.

3-1. Bundle files together

$ zip report.zip data.csv memo.txt
  adding: data.csv (deflated 62%)
  adding: memo.txt (deflated 20%)
Lina: What does deflated 62% mean?
Linny-senpai: It means "shrunk by 62%." zip reports the compression ratio for you. The first name, report.zip, is the file being created, and the rest are the files going inside.

3-2. Compress a whole directory (-r is required)

$ zip -r project.zip project/

The key gotcha: when compressing a directory, -r (recursive — include everything inside) is required. Forget -r and you'll get a nearly empty zip with no contents.

Lina: tar also treated directories specially.
Linny-senpai: Good memory! In zip, -r plays that role. Make it a reflex: bundling a directory means adding -r.

4. Extract with unzip

Conclusion: unzip name.zip extracts into the current directory. Use -d to set a target so files don't scatter.

4-1. Extract into the current directory (basic)

$ unzip report.zip
Archive:  report.zip
  inflating: data.csv
  inflating: memo.txt
Lina: inflating means "expanding," so it's extracting.
Linny-senpai: Right. Compression is deflate (shrink), extraction is inflate (expand). They're a pair.

4-2. Set the target directory (-d prevents accidents)

$ unzip report.zip -d ~/work/report

Avoid clutter: with no target, unzip dumps files right where you are. For archives with many files, pointing -d at a dedicated directory keeps things tidy. If the directory doesn't exist, unzip creates it for you.

5. Inspect contents before extracting

Conclusion: unzip -l name.zip lists contents without extracting. Always inspect an unfamiliar zip before opening it.

Lina: I'm a bit nervous opening a zip I received without looking first...
Linny-senpai: Healthy instinct. Add -l (list) and you can see just the file listing, without extracting.
$ unzip -l report.zip
Archive:  report.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
     1024  2026-06-05 10:00   data.csv
      256  2026-06-05 10:00   memo.txt
---------                     -------
     1280                     2 files

For safety: for a zip from someone you don't know, always check the contents with unzip -l before extracting. Watching for odd paths like /etc/... or unfamiliar files is a habit that prevents accidents.

6. When filenames come out garbled

Conclusion: If non-ASCII names from a Windows zip look garbled, on Ubuntu use unzip -O CP932 name.zip to extract them correctly.

Lina: I opened a zip from a Windows user and the filenames turned into gibberish like \203t\202@...!
Linny-senpai: That's the number-one snag in Windows interop. Windows sometimes stores non-ASCII filenames in a legacy encoding such as CP932 (a Shift-JIS variant), which clashes with Linux's UTF-8 and looks garbled.

The unzip on Ubuntu and Debian has an -O option to specify the filename encoding.

$ unzip -O CP932 windows.zip

Why this fixes it: -O CP932 tells unzip "the filenames in this zip are written in CP932." unzip then converts them correctly to UTF-8, and the names display properly. It works for inspection too: unzip -O CP932 -l windows.zip.

Lina: Just adding -O CP932 fixed it!
Linny-senpai: -O is a handy option in the Ubuntu / Debian build of unzip. Some systems don't have it, but if you deal with Windows it's well worth knowing.

7. Working with password-protected zips

Conclusion: zip -e makes an encrypted zip, and unzip prompts for the password on extraction. Classic zip encryption is weak — don't over-rely on it.

7-1. Compress with a password

$ zip -e secret.zip data.csv
Enter password:
Verify password:
  adding: data.csv (deflated 62%)

7-2. Extract a password-protected zip

$ unzip secret.zip

You'll be prompted for the password; enter it to extract.

Don't over-rely on it: traditional zip encryption is not strong. For genuinely sensitive files, don't depend on a zip password alone — consider a dedicated encryption tool or a secure transfer channel.

Practice: get your hands moving

Conclusion: Run the full flow yourself — compress, then inspect, then extract to a chosen target — to make it stick.

Linny-senpai: Let's run today's flow end to end: "bundle it, peek inside, open it safely" — three steps.

Exercise 1: compress a directory

Task: create a directory called mydata with some files inside, then compress it into mydata.zip.

Hint: use mkdir, touch, and zip -r.

Sample answer:

$ mkdir mydata
$ touch mydata/a.txt mydata/b.txt
$ zip -r mydata.zip mydata/

Exercise 2: inspect, then extract

Task: list the contents of mydata.zip, then extract it into a directory called extract.

Hint: unzip -l to inspect, unzip -d to set the target.

Sample answer:

$ unzip -l mydata.zip
$ unzip mydata.zip -d extract
$ ls extract/mydata
a.txt  b.txt
Lina: "Bundle, peek, open" — done! This flow feels safe.
Linny-senpai: Perfect. Make those three steps a habit and you'll stay calm with any zip that comes your way.

Common mistakes and fixes

Conclusion: Four classics — forgetting -r, command not found, scattered extraction, and garbled names. Learn each cause with its fix.

Mistake 1: compressed a directory but it's empty

Lina: I ran zip backup.zip myfolder but it has almost nothing inside.
Linny-senpai: Forgot -r. Bundle directories with zip -r backup.zip myfolder/. It's a really common slip.

Mistake 2: unzip: command not found

Lina: I typed unzip and got command not found.
Linny-senpai: The package isn't installed. Run sudo apt install unzip. If you also want to create zips, you'll need the zip package too.

Mistake 3: extraction cluttered my current directory

Lina: I opened a zip full of files and my current folder is now a mess...
Linny-senpai: unzip extracts to the current directory by default. Next time, send output to a dedicated directory with unzip xxx.zip -d target/. Running unzip -l first to see how many files are inside helps too.

Mistake 4: garbled filenames

Lina: Filenames from a Windows zip come out garbled.
Linny-senpai: On Ubuntu / Debian, unzip -O CP932 xxx.zip usually fixes it. The cause is Windows storing the names in CP932.

Summary

Conclusion: Bundle with zip -r, peek with unzip -l, extract safely with unzip -d. Garbled names? -O CP932. That pattern covers Windows interop.

  • Create: zip -r archive.zip dir/ (directories require -r)
  • Inspect: unzip -l archive.zip (check before extracting)
  • Open: unzip archive.zip -d target/ (no clutter)
  • Garbled names: unzip -O CP932 windows.zip (Ubuntu / Debian)

Next Reading