LinuxCommandLibrary

zipgrep

Search files inside ZIP archives

TLDR

Search for a pattern within a Zip archive

$ zipgrep "[search_pattern]" [path/to/file.zip]
copy

Print file name and line number for each match
$ zipgrep [[-H|--with-filename]] [[-n|--line-number]] "[search_pattern]" [path/to/file.zip]
copy

Search for lines that do not match a pattern
$ zipgrep [[-v|--invert-match]] "[search_pattern]" [path/to/file.zip]
copy

Specify files inside a Zip archive from search
$ zipgrep "[search_pattern]" [path/to/file.zip] [file/to/search1] [file/to/search2]
copy

Exclude files inside a Zip archive from search
$ zipgrep "[search_pattern]" [path/to/file.zip] [[-x|--line-regexp]] [file/to/exclude1] [file/to/exclude2]
copy

SYNOPSIS

zipgrep [grep_options] pattern zipfile [zipfile ...]

PARAMETERS

grep_options
    Any standard grep options. Common ones include: -i (ignore case), -n (show line numbers), -v (invert match), -w (match whole words), -r (recursive search - if supported), -l (list only file names containing matches), -c (count matching lines per file)

pattern
    The regular expression to search for within the zip archive(s).

zipfile
    The name of the zip archive file(s) to search. Multiple zip files can be specified.

DESCRIPTION

The zipgrep command is a utility used to search for lines matching a pattern within zip archive files.
It operates similarly to the standard grep command, but instead of searching plain text files, it directly searches the contents of compressed files within the zip archive without needing to extract them first.
This can be particularly useful for searching large archives or when you only need to find specific information without fully unzipping the entire archive. zipgrep supports various grep options, allowing you to perform complex searches using regular expressions, ignore case sensitivity, print line numbers, and more. It efficiently scans the archive, decompressing only the necessary files for searching, making it a time-saving tool for working with zipped data.
It does not modify the zip file, only outputs the results of the search to standard output.

CAVEATS

Not all grep features may be fully supported, and behavior can vary slightly across implementations. Some implementations might not support all grep options. If using the `-r` option for recursive search, be aware that the way it handles nested archives might vary. Zip files are read only, therefore this command will never modify a zip file.

EXIT STATUS

The zipgrep command returns an exit status of 0 if matches are found, 1 if no matches are found, and 2 if an error occurred.

SEE ALSO

grep(1), zip(1), unzip(1), zgrep(1)

Copied to clipboard