1

Is there a command to extract a set of zip files within another zip file and not extracting all of it ? eg:

A.zip has (B.zip, C.zip, c_directory, d.txt) How can extract B.zip and C.zip without extracting c_directory nor d.txt ?

We need to compare the contents in B.zip and C.zip and look for their differences by comparing their files sizes within them.

thanks all.

1 Answer 1

0

According to man unzip:

NAME
   unzip  -  list, test and extract compressed files in a ZIP ar‐
   chive

SYNOPSIS
   unzip   [-Z]   [-cflptTuvz[abjnoqsCDKLMUVWX$/:^]]   file[.zip]
   [file(s) ...]  [-x xfile(s) ...] [-d exdir]


  [file(s)]
          An optional list of archive members  to  be  processed,
          separated  by  spaces.   (VMS  versions  compiled  with
          VMSCLI defined must delimit files with commas  instead.
          See  -v  in OPTIONS below.)  Regular expressions (wild‐
          cards) may be  used  to  match  multiple  members;  see
          above.   Again, be sure to quote expressions that would
          otherwise be expanded or modified by the operating sys‐
          tem.

In other words, arguments given after the archive name are taken to be the list of files you want extracted:

$ unzip A.zip B.zip C.zip 

If you want to compare the contents of two zip files, you could just list the files in each archive and compare the lists. The options -lqq will cause unzip to list the files in an archive:

 $ unzip -lqq A.zip 
  424  2013-03-24 04:39   B.zip
  424  2013-03-24 04:39   C.zip
  424  2013-03-24 04:39   d.txt

So, to compare two archives, list the files in each, save into a text file and compare the text files:

$ unzip -lqq A.zip | sort > A_files.txt
$ unzip -lqq D.zip | sort > D_files.txt
$ diff A_files.txt D_files.txt | grep '<\|>'
<         0  2013-03-24 04:57   only_in_A.txt
>         0  2013-03-24 04:57   only_in_D.txt
4
  • terdon thanks for responding. what's the standard practice in comparing files in zip files; we have an issue where there were some missing files in a newer zip file but no one caught it. We like to set up a way in script to protect us from this happening again. Do you have a suggestion ? Greatly appreciated
    – chz
    Mar 24, 2013 at 3:48
  • @chz see updated answer, just list the contents and compare them using diff.
    – terdon
    Mar 24, 2013 at 4:00
  • Hi terdon i tried to accept your answer but I could not update it because of my low score; Thanks for your answers there; I still another question but I'll at another time
    – chz
    Mar 25, 2013 at 20:11
  • @chz feel free to ask more questions! Also, feel VERY free not to accept or upvote an answer if it has not helped you. My comment on your other question was not a complaint because you have not accepted my answers, I was just explaining how this site works. Also, you should always be able to accept an answer to your question, it has nothing to do with reputation. See here. When you are a new user you cannot upvote but you can always accept.
    – terdon
    Mar 25, 2013 at 20:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .