Issue
I have an entire directory structure with zip files. I would like to:
- Traverse the entire directory structure recursively grabbing all the zip files
- I would like to find a specific file "*myLostFile.ext" within one of these zip files.
What I have tried
1. I know that I can list files recursively pretty easily:
find myLostfile -type f
2. I know that I can list files inside zip archives:
unzip -ls myfilename.zip
How do I find a specific file within a directory structure of zip files?
Solution
You can omit using find for single-level (or recursive in bash 4 with globstar
) searches of .zip
files using a for
loop approach:
for i in *.zip; do grep -iq "mylostfile" < <( unzip -l $i ) && echo $i; done
for recursive searching in bash 4:
shopt -s globstar
for i in **/*.zip; do grep -iq "mylostfile" < <( unzip -l $i ) && echo $i; done
Answered By - David C. Rankin Answer Checked By - Mary Flores (WPSolving Volunteer)