I only know the filename but not its exact location. I would like to extract only that file from the archive. And I need to know its location in the archive.

  • 1
    unzip -l archive.zip will provide a listing. Use -h or --help on many/most commands for basic usage – bsd Apr 3 '14 at 10:43
  • @bdowning Thanks, and how do I get the path of a specific file from the list? – aneuryzm Apr 3 '14 at 10:44

unzip accepts wildcards and globs. If you know the filename, then you could simply say:

unzip archive.zip "**/file_to_extract"

in order to extract the said file.


As a synthesis of both comment and answer, you could proceed like this:

unzip -l archive.zip | grep "nameOfile"
#identify the path of the file precisely in your archive if filtering gives you several result and then use 
 unzip archive.zip ./ham/smoked/nameOfile

This should work


Mount the zip archive as a filesystem with fuse-zip. Then you can access files in it using any command you like.

mkdir foo
fuse-zip foo.zip foo

Then, to copy needle.txt from whichever subdirectory it's in:

find foo -name needle.txt -exec cp -p {} . \;

Or using the shell's recursive globbing (in bash, you need to run shopt -s globstar first; in zsh this works out of the box):

cp -p foo/**/needle.txt .

Unmount the filesystem when you've finished using it.

fusermount -u foo

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.