Ledge

How to extract one file from a zip on a Mac without unzipping it all

Double-clicking a zip on a Mac always expands the whole thing, and Finder has no way to look inside one first. To take out a single file, use Terminal: unzip -l lists what the archive holds, and unzip followed by the archive and the file’s name extracts only that file. It takes two commands and works on archives of any size.

What double-clicking does

Double-click a .zip and Archive Utility expands every item into the folder the zip is sitting in. There is no window, no list of contents and no way to pick. Pressing Space for Quick Look does not help either: it shows the archive’s name and size, not what is inside.

For a zip holding a few documents, that is fine. Expand it, take what you need and drag the rest to the Trash. It becomes a problem when the archive is large. A photo export or a project backup of several gigabytes takes a while to expand, needs free space for everything in it, and leaves you a folder to clean up afterward, all for the sake of one file.

List what is inside

Open Terminal from Applications > Utilities and type unzip -l followed by a space. Then drag the zip from Finder into the Terminal window; Terminal types the full path for you. Press Return.

unzip -l ~/Downloads/site-backup.zip

You get a table with one line per item: its size, the date it was last changed, and its path inside the archive. Nothing is extracted. The path in the last column is what you need for the next step, exactly as printed, including any folders in front of the file name.

Two things to know when you read the list:

  • Zips made on a Mac often contain entries that start with __MACOSX/ and files named .DS_Store. Those are Finder housekeeping, not your documents. Ignore them.
  • A long list scrolls past quickly. To find one name, add a filter: unzip -l ~/Downloads/site-backup.zip | grep -i invoice shows only the lines containing “invoice”, in upper or lower case.

Extract a single file

Give unzip the archive, then the path of the file inside it in quotes, then -d and the folder to put it in:

unzip ~/Downloads/site-backup.zip "site/docs/invoice-march.pdf" -d ~/Desktop

Only that file is written. The quotes matter whenever the name contains a space, and they do no harm when it does not.

By default unzip recreates the folders from the archive, so the command above produces site/docs/invoice-march.pdf on the desktop, nested two folders deep. If you want the file by itself with no folders around it, add -j:

unzip -j ~/Downloads/site-backup.zip "site/docs/invoice-march.pdf" -d ~/Desktop

A few details:

  • If a file with the same name is already at the destination, unzip stops and asks whether to replace it, skip it or rename it. Add -n to make it never replace anything.
  • If the archive has a password, unzip asks for it in the Terminal window. Nothing appears as you type, which is normal. Press Return when you are done.
  • The message “caution: filename not matched” means the path you gave is not exactly what the archive holds. Copy it from the listing, folders included, and check the capitalization.

Extract one folder or one type of file

The same command takes patterns. Always quote them, so Terminal passes the pattern to unzip untouched. Without quotes, the shell tries to match the pattern against the folder you are in and stops with “no matches found”.

One folder and everything in it:

unzip ~/Downloads/site-backup.zip "site/images/*" -d ~/Desktop

Every PDF anywhere in the archive:

unzip ~/Downloads/site-backup.zip "*.pdf" -d ~/Desktop/pdfs

The pdfs folder is created if it does not exist. Patterns are case-sensitive, so *.pdf skips a file ending in .PDF. Add -C to match either case.

Be careful when you combine -j with a pattern. With the folders stripped away, two files that share a name in different parts of the archive are headed for the same spot, and unzip will ask what to do about the second one.

Getting the path in and the file out

The Terminal route has two bits of friction that have nothing to do with unzip itself. The first is getting the zip’s path into the command. The second is getting the extracted file from the desktop to wherever it was needed.

Dragging the zip from Finder into Terminal works when both windows are visible at the same moment. Often they are not: Terminal is full screen, or the zip is in a folder three windows down. Paste a file path into a terminal the easy way covers the built-in options, and paths with spaces in the terminal explains why typing the path by hand tends to go wrong.

Ledge takes the window arranging out of it. Drag the zip up to the notch at the top of the screen and let go; it lands on a shelf that drops from the notch and stays there. Switch to your terminal, type unzip -l and a space, open the shelf with Option-Space or a click on the notch, and drag the zip onto the terminal window. A terminal can use a path and cannot use a file, so the path is what it receives, as text. The first time it pastes a path this way, macOS asks for Accessibility permission. Ledge does not ask at launch, only when that step is first needed.

The trip out is the same shelf in the other direction. Once the file is extracted, drag it up to the notch, go to the app that was waiting for it, and drag it off. Dropped on a chat app, it uploads. Dropped on a Finder window, the file itself moves into that folder. Dropped on a terminal, it arrives as a path again. You do not choose a format at any point; each destination gets the form it can use. If you would like to reveal the extracted file from the command line first, getting a file out of the terminal and into another app shows how.

To be plain about the limits: Ledge does not open, list or expand archives, and it does not read or index your files. A zip on the shelf is still a zip. The extracting is done by unzip, which ships with macOS. What the shelf adds is a place to put the archive down, and later the extracted file, while you get the right window in front of you.

Everything here happens on the Mac, which matters when the archive holds something private. Online extractors need the whole zip uploaded to give you one file back. unzip reads it where it sits, and Ledge has no account and no cloud.

Questions

Can I see what is in a zip without Terminal?

Not with what ships in macOS. Finder and Quick Look treat a zip as one sealed item, and Archive Utility only expands. The listing command is the built-in way to look before you extract.

Does extracting one file change the zip?

No. unzip only reads the archive. The zip is the same size with the same contents afterward, and you can extract from it again as often as you like.

Where does Archive Utility put files when I do double-click?

In the same folder as the zip. To change that, open Archive Utility with Spotlight and choose Archive Utility > Settings, where you can pick a different folder for expanded files and decide what happens to the archive afterward.