50

If I have an archive, for example, some.zip that contains one or more files, how can I extract only one file (I know the name of the file) with 7-Zip from the command line in Windows?

5 Answers 5

17

You just add the filename at the end.

7z e [archive.zip] -o [outputdir] [fileFilter]
4
  • 1
    How can I add multiple file filters, say .XML and .zip? Sorry if I'm hijacking this thread, I just didn't want to add a duplicate question.
    – Fr0zenFyr
    Jun 21, 2014 at 5:25
  • It's a different question @Fr0zenFyr. To make it clear that it is not duplicate, you can reference this question in your own, and then specify how yours is different. Jan 23, 2017 at 23:18
  • @music2myear: Thanks for clarification. Top voted answer by zionyx already includes a solution. My comment is over 2 years old, so it would be a reasonable guess to assume that I either used above solution or already posted a question and found an answer (BTW, this was my case). My resolved post is on SO and original thread created before my comment is here so I couldn't link to this question. :)
    – Fr0zenFyr
    Jan 25, 2017 at 10:00
  • 1
    Note : as it is written here, do not put space between -o and outputdir. Oct 25, 2019 at 9:38
45

As a follow-up to surfasb's answer, add a -r flag at the end to recurse:

7z e [archive.zip] -o[outputdir] [fileFilter] -r

Multiple filters support:

7z e [archive.zip] -o[outputdir] [fileFilter_1] [fileFilter_2] -r

Example:

Multiple filters command line:

7z e archive.zip -o outputdir *.xml *.dll -r

PS: I use 7za.exe instead of 7z.exe. This is the actual command I use in my script:

7za.exe x archive.zip -o outputdir *.xml *.pdb *.exe *.ocx *.dll -r
6
  • 2
    How can I add multiple file filters, say .XML and .zip? Sorry if I'm hijacking this thread, I just didn't want to add a duplicate question.
    – Fr0zenFyr
    Jun 21, 2014 at 5:25
  • 2
    Should be fine by separating the filters by space. See the edited answer above. :)
    – zionyx
    Aug 26, 2014 at 14:06
  • And how do I extract a specific file from an archive inside the archive? Lets say the file I'm looking for is "MyFile.txt" inside "SubArchive.zip" inside "MainArchive.zip". Is this possible?
    – PeterCo
    Oct 27, 2017 at 12:14
  • 1
    @PeterCo, I think the command is only capable to extract SubArchive.zip from the MainArchive.zip in your case. You may run a follow up command to extract MyFile.txt from SubArchive.zip after the initial extraction.
    – zionyx
    Jan 5, 2018 at 9:09
  • You also want to double-quote those wildcard filters, e.g. ".exe" or ".pdf". Without that, the filter will skip filenames with embedded space characters.
    – Dave Hein
    May 22, 2021 at 12:31
7

If you look at the man page for 7z you will find that the following command can be used to extract a file from a 7z archive (though the usage of path is missing from the man page):

7z x <archive> <path to file>

Examples:

7z x backup.7z *.html
7z x backup.7z folderwithin/myfile.html

Alternatively you could use e.

The command line version users guide seems to have more information on the actual usage.

2
  • 2
    Is that the relative path within the archive? Jan 23, 2017 at 23:18
  • Yes, the "folderwithin" is a folder at the root of the archive. Oct 25, 2019 at 8:37
3

Note that 7z has the following syntax (observe the spaces and quotes surrounding the "-oMy Folder" option to set the output folder name, took me hours to figure out, as I originally did this – the wrong way: * -o "My Folder" *):

7z e "my zip.zip" "-oMy Folder" *.jpg "all of these.*" -r
1
  • Thank you so much.
    – Ali
    May 29, 2020 at 16:14
0

I found that on zsh command line, with 7-zip 16.06, that I had to put double-quotes around the wildcard filter argument. For example, this did not find any PDF files to extract:

7z e "archive has pdf in subdirectory.zip" -r *.pdf

but quoting the wildcard filter did find and extract the PDF file that was in a subdirectory of the zip archive, like this:

7z e "archive has pdf in subdirectory.zip" -r "*.pdf"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.