I am looking for a way to search the content of files inside of a 7-Zip archive (.7z) without having to unpack the archive. I have many 7-Zip archives with code inside them and I'd like to search them.
Is there a way to do that?
58 Answers
On Windows, use a command prompt:
cd C:\Program Files\7-Zip
7zTo search for a specific file, e.g. namefile:
7z l compressed.tar namefile -rVideo tutorial: Search files with 7-Zip
3WinRAR can do it. However, let's face that fact it involves unpacking it, even though WinRAR does it seamlessly.
As others have said, no there is no way. To examine the contents of a file, it needs to be unpacked (regardless of if the files are compressed solid or not or if they are encrypted or not). The only way that you can avoid having to decompress the files is if they are added with the store method (ie, not compressed at all, just globbed together).
Try out SearchInZipFiles: It is a simple Open Source Tool for Windows located on Sourceforge:
dnGrep is an excellent Windows grep implementation that has an archive file plugin that works with all archive formats. You can use Regex, Xpath, Text, or phonetic for your search.
1If you're on Linux with 7-Zip installed:
find . -iname *7z -exec 7zr -l \{\} \; | grep "filename.cpp" 3 On Windows, there exist a few utilities that can search the contents of files inside compressed archives with no decompression. Below are a couple of such products:
dnGrep
Free and open-source, it can search zip, 7z, rar, jar, and many more archive formats. It also displays a preview of the found text in the files contained inside the archive. I tested it and it works as claimed.MythicSoftFileLocator Pro and Agent Ransack (commercial)
Both products advertise their capability for searching compressed archives, but I have not tested it.
It seems that it's not possible with 7z out-of-the-box, without decompressing it to a temporary storage.
I hope there is a nice solution that someone will post to solve this (thus the bounty I started).
However:
it's possible for .gz files:
zgrep "hello" foo.txt.gzit's possible for .xz files:
xzgrep "hello" foo.txt.xzSee .
Note that .xz files use the same compression algorithm than .7z, LZMA2, but it only compresses one file and not many files, except if you use tar (but that's out of topic here).
Conclusion: if you want to archive with a good compression ratio (similar to 7z), in a format that is searchable easily from command-line, use .xz instead of .7z.