Zipgrep - How to search through zip files in Linux
zipgrep - search for files in a ZIP archive for lines matching a specific expression. zipgrep is an piece of shell script which uses unzip and egrep
- Published
- Reading time
- 2 min

Zipgrep is an amazing tool to search through zip archive for a specified pattern. Zipgrep is just a piece of shell script which leverage the usage of unzip and egrep to run. Zipgrep process given expressions just as egrep.
Zipgrep – Usage
Since it’s a just a wrapper script for unzip and grep, it’s input and output process is a lot similar to the egrep . Zipgrep searches for text strings inside the files contained in the archive, not the filenames that zip archive contains. Note that the command syntax is:search pattern + archivename + optional list of filenames to search.
#zipgrep pattern filename
For instance if you have a file named “h-books” with the following list:
- Metasploit: The penetration tester’s guide
- Hacking: The Art of Exploitation, 2nd Edition
- The Basics of hacking and Penetration Testing
- CEH Certified Ethical Hackers All-in-one Exam Guide
- Black Hat Python: Python Programming for Hackers and pen-testers
And you also have another file called “l-books” with the following list:
- How Linux Works: What Every Superuser Should Know by Brian Ward
- The Linux Programming Interface: A Linux and UNIX System Programming Handbook by Michael Kerrisk
- Unix and Linux System Administration Handbook by Evi Nemeth
- Linux in a Nutshell: A Desktop Quick Reference
- The Linux Command Line – A Complete Introduction by Williams E. Shotts
Now these two files have been compressed using the zip format into a file called “library.zip“. Now you can use the zipgrep command to find patterns within all the files within the zip file.
For example, if you wanted to search for all the occurrences of “hacking” you would use the following command:
zipgrep "hacking" library.zip
The result will be:
[user@hostname ~]$ zipgrep "Hacking" library.zip library/h-books:Hacking: The Art of Exploitation, 2nd Edition library/h-books:The Basics of Hacking and Penetration Testing [user@hostname ~]$

As you can see, you can use any expression with zipgrep that you use with grep or egrep, this makes the zipgrep tool very handy, and it makes looking for zip files much easier than decompressing, searching and then compressing again.
If you only want to search specific files within the zip archive you can give the certain files names to search within the zip archive as part of the command shown below:
zipgrep "Linux" library.zip l-books
If you want to exclude the certain files from your search process, you can use the following command as an example:
zipgrep "Program" library.zip -x h-books
This will result in same output as before as it will search all files within library.zip except for excluded file “h-books”.
Written by
A Computer Science Graduate, who works extensively on open source projects. His Areas Of interest are: Network Security, Linux Administration, FOSS, Python, and C programming.
More from Ajay →$ grep -r "linux" ~/articles
Keep reading

Understanding Grub Edit: A Comprehensive Guide
Introduction Grub (Grand Unified Bootloader) is a popular bootloader used in most Linux systems. It is responsible for loading the operating system into the…
2 min read

How to Check if a Bash String Contains a Substring
Introduction When writing Bash scripts, it is often necessary to check if a string contains a specific substring. This can be useful for performing conditional…
3 min read

Grep Ignore Case: A Step-by-Step Guide
Introduction Grep is a powerful command-line utility used for searching text files for specific patterns. However, by default, grep is case-sensitive, which…
2 min read
