1

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).

1
  • 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, 2013 at 16:06

3 Answers 3

0

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

1
  • 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, 2013 at 20:43
0

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.

and

zcat  is identical to gunzip -c.

On Debian linux

zgrep

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

1
  • 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, 2013 at 20:37
0

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).

You must log in to answer this question.

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