I run Linux Live CD and I need to extract a specific file from a wim-archive that is located on a disk drive. I know a full path to the file in the archive:

xubuntu@xubuntu:~$ 7z l winRE.wim | grep -i bootrec.exe
2009-08-28 15:02:29 ....A       299008       134388  Windows/System32/BootRec.exe

I am short on disk space and do not have a possibility to unpack the whole archive.

How could I extract that specific file from the archive?

I tried the -i option, but that did not work:

xubuntu@xubuntu:~$ 7z x -i Windows/System32/BootRec.exe winRE.wim 

Incorrect command line

3 Answers 3


The man 7z page says:

         Include filenames

You need to explicitly specify ! before the file name and protect the switch from bash expansion with single quotes: 7z x '-i!Windows/System32/BootRec.exe' winRE.wim

xubuntu@xubuntu:~$ 7z x '-i!Windows/System32/BootRec.exe' winRE.wim

7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,4 CPUs)

Processing archive: winRE.wim

Extracting  Windows/System32/BootRec.exe

Everything is Ok

Size:       299008
Compressed: 227817568

(You can avoid keeping the full path by using the e function letter: 7z e '-i!Windows/System32/BootRec.exe' winRE.wim.)

BTW, if you do not protect the -i option with single quotes or protect it with double quotes, you get an error:

xubuntu@xubuntu:~$ 7z x "-i!Windows/System32/BootRec.exe" winRE.wim 
bash: !Windows/System32/BootRec.exe: event not found
  • You really don't need a wildcard for single file, yet it is useful for extracting all files with pattern. Jul 21, 2021 at 8:51
7z e [archive name] -o[direction] [filename] -r

for example:

7z e 'Movies.rar' -o/root/Downloads/ 'Rush.mp4' -r

This command worked for me, I tried it on ubuntu server 16.04.


Worked for me (you may want to use forward slashes instead, see below):
7z e -so 'file.zip' 'file\path\file.png' > 'file.png'
(One PNG file extracted from the ZIP file: the command will create or OVERWRITE any file named "file.png" in the current directory. e: extract keeping filename but not keeping file path. -so: output to stdout.)

Did NOT work for me:

7z e 'file.zip' 'file.png' -r
7z e 'file.zip' -o. 'file.png' -r
7z e 'file.zip' -o'.' 'file.png' -r
7z e '-i!file.png' 'file.zip'
7z e '-i!file/path/file.png' 'file.zip'
7z e '-i!/file/path/file.png' 'file.zip'

Why did those commands not work for me, but that one command did? Maybe because the folder separators in the file paths in the ZIP file were backslashes instead of the normal forward slashes. Maybe I should have ran those commands with backslashes (\) or escaped backslashes (\\), then it would have worked.

If you have a ZIP file with the discouraged backward slashes (https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT § in file paths apparently you can also extract an individual file from it via the following unzip command:
unzip -p file.zip 'path\\to\\file.png'

(Credit: https://archived.moe/g/thread/85892819#85900314)

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.