1

I have a .zip file (it contains multiple files, e.g., file1.txt, file2.txt, file3.txt) in a directory.

How can I extract the files from the zip archive into the very same directory? And how can I create the list of all the files extracted from the zip archive?

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

file1.txt
file2.txt
file3.txt
filen.txt

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

unzip -qoj data.zip | unzip -ql data.zip  > file_list 

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

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 a Linux command, or do I have to write a perl script for this?

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

Your Answer

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