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
zipto compress files and directories into a .zip - Use
unzipto 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.
report.zip. Can I open it on Linux?.zip is exactly what Windows creates when you right-click and "compress." On Linux you open it with unzip and create one with zip.tar we learned before?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.
zip and tar.| 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.
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.
unzip: command not found...$ sudo apt install zip unzip
zip and unzip together?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-ras inzip -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%)
deflated 62% mean?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.
tar also treated directories specially.zip, -r plays that role. Make it a reflex: bundling a directory means adding -r.4. Extract with unzip
Conclusion:
unzip name.zipextracts into the current directory. Use-dto 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
inflating means "expanding," so it's extracting.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.ziplists contents without extracting. Always inspect an unfamiliar zip before opening it.
-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.zipto extract them correctly.
\203t\202@...!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.
-O CP932 fixed it!-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 -emakes 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.
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
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
zip backup.zip myfolder but it has almost nothing inside.-r. Bundle directories with zip -r backup.zip myfolder/. It's a really common slip.Mistake 2: unzip: command not found
unzip and got command not found.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
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
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)