Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a .zip file (It contains multiple files, ex: file1.txt file2.txt file3.txt.. n so on) in a directory.

And my query is:

How to extract the files from .zip archive to the very same directory and how to create the list of all the files extracted from .zip archive.**

The extracted file name should be printed like this in the file named: file_list:


I have tried the following command assuming that my .zip file name is "".

unzip -qoj | unzip -ql  > file_list 

I have used unzip -qoj to extract all the files in the same directory(quietly,overwrite,junk_path). When I try to insert -l with the first unzip command then the command doesn't extract the file in the current and only files are listed thats why I have to used unzip again after the first pipe(If I am making a mistake here let me know please).

I get the following output

 Length     Date   Time    Name
 --------    ----   ----    ----
        0  12-21-09 14:25   data/
     6148  12-21-09 14:25   data/.DS_Store
        0  12-21-09 14:25   __MACOSX/
        0  12-21-09 14:25   __MACOSX/data/
       82  12-21-09 14:25   __MACOSX/data/._.DS_Store
       82  12-11-09 13:59   data/file1.txt
      120  12-11-09 13:59   data/file2.txt
      166  12-11-09 13:59   data/file3.txt
 --------                   -------
     6598                   8 files

How do I extract only file1.txt file2.txt file3.txt from this stdout?

Is it possible to do this with linux command or I have to write a perl script for this?

Thank you.

share|improve this question

migrated from Feb 24 '10 at 1:55

This question came from our site for professional and enthusiast programmers.

unzip data/file1.txt data/file2.txt data/file3.txt
share|improve this answer
what if I have 100 files in .zip archive? – Suren Feb 23 '10 at 21:16
unzip -l|gawk '$NF~/^data\/file.\.txt$/{print $NF;}'|xargs unzip -qoj – jch Feb 24 '10 at 16:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.