How do I use grep to find all the zip files in a directory?

I have a directory with over 1000 files, and a few of them are .zip files, and I want to turn them all into .tgz files.

I want to use grep to make a list of file names. I have tried "grep *.zip" to no avail. Reading the man pages, I thought that * was a universal selector. Why is this not working?

Thank you.


You should really use find instead.

find <dir> -iname \*.zip

Example: to search for all .zip files in current directory and all sub-directories try this:

find . -iname \*.zip

This will list all files ending with .zip regardless of case. If you only want the ones with lower-case change -iname to -name

The command grep searches for strings in files, not for files. You can use it with find to list all your .zip files like this

find . |grep -e "\.zip$"

Grep uses regular expressions by default. The expression you'd want is:

grep .zip$

You probably want to use find though.

find . -name '*.zip'

Or you can pipe find into grep

find . | grep .zip$