Is there some method to find, from the shell, all files matching a file pattern including those inside archives (specifically: zip archives)?

The simulation package "VASP" produces files called "OUTCAR" amongst others. Those files are now distributed over hundreds of folders, most but not all of them, zipped to speed up incremental backups by reducing file clutter. I now want to run as script on all those zipped and non-zipped OUTCAR files.

Of course I could write a script that uses "find" to find the unzipped files and a combination of find, grep and unzip to find the zipped files, but a standard solution, if any, would be preferred, as it would allow to easily treat zip files like readonly-folders across my scripts.

Ideally there would be a set of commands emulating the behaviour of common shell commands like cat, grep, find except that they allow zip files as part of file names.

I would not require such tools to be able to handle nested zip files. The very reason I switched from .tar.gz to .zip is the existence of a file index accessible without extracting anything (quite a speed difference for 100 MB archives with high compression) which is partially lost when nested archives are involved.

On a side note, I am using Windows 7 with Cygwin (though that should make a difference only regarding the performance of process creation).

  • You want to find all files (zipped or not) whose name contains OUTCAR right? Not on the files that contain the string, only those that are named so? – terdon Jul 17 '13 at 16:06

You can list zip file content wint unzip command like this

 unzip -l file.zip

Edit : Actually this answer might be very helpful for what you are trying to accomplish

  • On Windows, even with cygwin, fuse is not feasible. I tried using Dokan once, but with no useful results. I suppose I'll just go for some glue code emulating find behaviour. – kdb Jul 18 '13 at 20:43

If you're on OSX, try the same utilities with a z prepended to their name. They will grep through both zipped and non zipped files.

From the man pages:

zgrep, zegrep, and zfgrep act like grep, egrep, and fgrep, respectively, but accept input files compressed with the compress(1) or gzip(1) compression utilities.


zcat  is identical to gunzip -c.

On Debian linux


is a script wrapper that unarchives the zip and greps through it so at least you wouldn't have to write that yourself.

  • These tools don't work on zip archives. Judging from the error message they would work, if it contained but a single file, but that is not the purpose of *.zip archives. – kdb Jul 18 '13 at 20:37

It should only be a few minuets work to extend the python os.walk example to a) list the files that match your pattern, (using re on the file lists) and b) when it meets a zipped/tared/etc file open them using the appropriate library and pattern match the file names inside. (Sorry can't actually write it for you as I have to get off to work).

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.