64

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?

Kiesoo
  • 743

5 Answers5

61

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
zionyx
  • 779
29

You just add the filename at the end.

7z e [archive.zip] -o [outputdir] [fileFilter]
surfasb
  • 22,896
10

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.

Seth
  • 9,393
6

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
3

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"
Dave Hein
  • 131