Chapter 43: Bash Extract (unzip)
Bash Extract (unzip), which means the unzip command! 😄
This is the partner tool to the zip command we learned last time. While zip is the tool that creates .zip files (compress + archive), unzip is the tool that extracts (opens/unpacks) .zip files so you can get your original files and folders back.
Think of it like this:
- zip = packing a suitcase very tightly
- unzip = opening that suitcase and taking everything out neatly
.zip files are everywhere — downloaded from websites, shared via email/WhatsApp/Google Drive, sent by Windows friends, attached in job applications, theme packs, plugin downloads, backup archives — so unzip is one of the most useful commands you’ll use almost every week.
Step 1: Make Sure unzip is Installed
Most Linux systems come with it, but check:
|
0 1 2 3 4 5 6 7 8 |
unzip -v # or unzip --version |
If you get “command not found”:
|
0 1 2 3 4 5 6 7 8 9 10 |
sudo apt update && sudo apt install unzip # Ubuntu / Debian / Pop!_OS # or sudo dnf install unzip # Fedora # or brew install unzip # macOS with Homebrew |
Basic Syntax
|
0 1 2 3 4 5 6 |
unzip [options] archive.zip [file(s) to extract] [-d destination_folder] |
- No extra arguments → extracts everything into current folder
- You can extract only specific files/folders
- -d = extract to a different folder (very safe & common)
1. Simplest Way – Extract Everything
|
0 1 2 3 4 5 6 |
unzip myproject.zip |
→ All files & folders inside myproject.zip come out into your current directory.
If the zip has a top-level folder (good practice), it creates that folder automatically:
|
0 1 2 3 4 5 6 7 8 9 10 |
Archive: myproject.zip creating: myproject/ inflating: myproject/index.html inflating: myproject/style.css ... |
2. Extract to a Specific Folder (Safest & Most Recommended!)
Use -d (destination):
|
0 1 2 3 4 5 6 |
unzip backup_2026.zip -d ~/extracted_backups/ |
→ Everything goes neatly inside ~/extracted_backups/ — no mess in your current folder.
Create folder first if you want:
|
0 1 2 3 4 5 6 7 |
mkdir temp_extract unzip photos.zip -d temp_extract/ |
3. Preview / List Contents Without Extracting (-l)
Super useful before extracting — check what’s inside!
|
0 1 2 3 4 5 6 |
unzip -l big_archive.zip |
Output example:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
Archive: big_archive.zip Length Date Time Name --------- ---------- ----- ---- 4096 2026-02-25 14:30 documents/report.pdf 12345 2026-02-24 09:15 photos/vacation1.jpg 567890 2026-02-20 18:45 code/project/main.py --------- ------- 580331 3 files |
See sizes, dates, file names — decide if you really want to extract.
4. Extract Only Specific Files or Folders
You can pick exactly what you want:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Extract single file unzip archive.zip important.pdf # Extract folder inside zip unzip archive.zip "my_folder/*" # Extract all .jpg files unzip photos.zip "*.jpg" -d images_only/ |
Note: use quotes if pattern has * or spaces.
5. Handle Overwriting Files (-o / -n)
By default unzip asks if a file already exists:
|
0 1 2 3 4 5 6 |
replace report.pdf? [y]es, [n]o, [A]ll, [N]one, [r]ename: |
Common options:
- -o → overwrite all without asking (careful!)
|
0 1 2 3 4 5 6 |
unzip -o update.zip |
- -n → never overwrite (skip existing files)
|
0 1 2 3 4 5 6 |
unzip -n backup.zip |
6. Password Protected Zip (-P)
If the zip was created with password:
|
0 1 2 3 4 5 6 |
unzip -P MySecret123 secure_files.zip |
Or it will prompt you:
|
0 1 2 3 4 5 6 7 |
Archive: secure_files.zip [secure_files.zip] password: |
7. Quick Practice Session (Try This Right Now!)
First create a zip to play with (if you did previous zip lesson):
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# If you have a zip file already → great! # Otherwise create quick test mkdir unzip_test cd unzip_test echo "Hello from Hyderabad" > note.txt zip test.zip note.txt # Now extract practice unzip -l test.zip # preview unzip test.zip # extract here unzip test.zip -d extracted/ # extract to folder cat extracted/note.txt # check content |
Now download a real sample zip (safe small one):
|
0 1 2 3 4 5 6 7 8 9 |
wget https://www.sample-videos.com/zip/10mb/sample-zip-file-10mb.zip unzip -l sample-zip-file-10mb.zip unzip sample-zip-file-10mb.zip -d sample_content/ ls sample_content/ |
Summary Table – unzip Commands You’ll Use Every Day
| What you want | Command Example | Best Practice Note |
|---|---|---|
| Extract everything | unzip archive.zip | Quick & simple |
| Extract to specific folder | unzip archive.zip -d ~/my_folder/ | Safest – always use this |
| Only preview contents | unzip -l archive.zip | Check before extract |
| Overwrite without asking | unzip -o update.zip | For updates/scripts |
| Never overwrite | unzip -n backup.zip | Protect existing files |
| Extract with password | unzip -P Secret123 file.zip | Or it will prompt |
| Extract only certain files | unzip archive.zip “docs/*” -d docs_only/ | Selective extract |
| See more details (verbose) | unzip -v archive.zip | Shows compression info |
Teacher’s Golden Rules
- Always use -d destination/ unless you’re 100% sure current folder is clean
- Always do unzip -l first on unknown zips (safety + curiosity)
- Never unzip suspicious files without checking (malware can hide in zips too)
- For .tar.gz, .tar.xz, etc. → use tar -xzvf or tar -xJf — unzip is only for .zip
Got it, boss? unzip is your key to open 90% of compressed files people send you — simple, reliable, and everywhere compatible.
Any confusion? Want next: “Teacher, explain unzip vs tar extract difference” or “how to unzip split zip files (.z01 .z02)” or “zip + unzip in scripts” or back to other compression tools?
Just say — teacher is waiting in Hyderabad! Keep extracting carefully! 🐧📦🔓 😄
