Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
1  
Use ls, not grep. –  Maxime R. Jan 19 '12 at 17:38
    
Wow, wow, wow. Thank you. –  David Faux Jan 19 '12 at 17:42

2 Answers 2

up vote 4 down vote accepted

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 regarding of case. If you only want the ones with lower-case change -iname to -name

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

find . |grep -e "\.zip$"
share|improve this answer
    
Thanks! This is recursive too. –  David Faux Jan 19 '12 at 17:45
    
Added some info on how to use find with grep if you're interested. –  Zoke Jan 19 '12 at 17:51

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$
share|improve this answer
1  
No need to pipe the results of find to grep, see above. –  bodhi.zazen Jan 19 '12 at 18:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.