Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have 348 zip files and I want to find a file that is in one of the zip files, unzip -l doesn't work with wild cards?

How can I list content of all .zip files and grep through the merged list of all files contained in the zips?

share|improve this question
add comment

3 Answers

up vote 9 down vote accepted

Using zipinfo is a fine solution here. However, in general whenever you want to apply a command to a list of files and the command doesn’t accept a list of files, you can use a for loop:

for file in *.zip; do
    unzip -l "$file"
done \
| grep "\.zip\|setup"

If the file you are searching for has spaces in it like: your file, in the grep regular expression you need to escape every space with a backslash like grep "\.zip\|your\ file".

share|improve this answer
    
Works perfectly the only problem is that it doesn't show the name of the zip, –  Eduard Florinescu Oct 5 '12 at 15:16
    
I edited you post and added regular expression to display also the filename where setup is found, +1 and accept –  Eduard Florinescu Oct 5 '12 at 15:23
    
Oh yes, I’d forgotten the quotes around the argument to unzip, how embarrassing. –  Konrad Rudolph Oct 6 '12 at 8:58
add comment

You can use zipinfo. It is included in the default Ubuntu installation. Check the manual page for more info.

For example, to look for a pattern setup in a bunch of zip files in current directory, use this command:

find ./ -iname *zip 2> /dev/null -print0 | xargs -0 zipinfo | grep setup
share|improve this answer
    
I get a caution: filename not matched: case1.zip... caution: filename not matched: case348.zip for every zip, tested on two Ubuntu OSs, 11.10 and 12.04. –  Eduard Florinescu Oct 6 '12 at 5:24
    
@EduardFlorinescu Try the updated answer. Though the answer was working for me –  Anwar Shah Oct 6 '12 at 5:39
    
the problem is that the file might contain that setup and it puts the same error, although it works like this: zipinfo -l * | grep "setup" –  Eduard Florinescu Oct 6 '12 at 5:42
    
I edited the answer. I think it is more robust now –  Anwar Shah Oct 6 '12 at 5:45
    
Thanks, +1 for effort, but still it will not work if zip file has spaces in its name. –  Eduard Florinescu Oct 6 '12 at 5:48
show 1 more comment

To list the files in a zip archive you can use the following command.

unzip -l

To grep a compressed archive you should use the compressed archive utilities built to work with that type of archive format.

For zip archives:

zipgrep --help  
usage: zipgrep [egrep_options] pattern zipfile [members...]
Uses unzip and egrep to search the zip members for a string or pattern.

For tar archives:

zgrep --help
Usage: /bin/zgrep [OPTION]... [-e] PATTERN [FILE]...
Look for instances of PATTERN in the input FILEs, using their
uncompressed contents if they are compressed.

OPTIONs are the same as for 'grep'.

There are a few other tools that work with archives as well. You can pipe the out put into grep to do the same thing.

zcat
zcat my.archive.zip | grep "some text"

Or you can use the search functionality of these tools

zless
zmore
share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.