Operating System - HP-UX
1826460 Members
3049 Online
109692 Solutions
New Discussion

'find' not finding all files using wildcards

 
SOLVED
Go to solution
Ron Levy
Advisor

'find' not finding all files using wildcards

I have a set of directories. Each directory will have approximately 50-200 files ending with .htm. I would like to devise a 'find' command to traverse these directories and gzip them all individually. Here are some of the commands I have tried, starting at the top of this set of directories:

find . -name *.htm -exec gzip {} \;
find . -name '*.htm' -exec gzip {} \;
find . -name "*.htm" -exec gzip {} \;
find . \( -name *.htm \) -exec gzip {} \;
find . \( -name '*.htm' \) -exec gzip {} \;
find . \( -name "*.htm" \) -exec gzip {} \;

None of them manages to find all the files in all the directories. They always leave some behind. Why is this?

Thanks,
-Ron Levy
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor

Re: 'find' not finding all files using wildcards

Hi Ron:

I would expect the unquoted format (either single or double quotes) to give problems because the shell is going to attempt to expand the filename before 'find' ever sees it.

With the quoted forms, do you expect to have files with any characters following the suffix "htm"? If so, you need to change your find to:

# find . -name '*.htm*'

Regards!

...JRF...
Rodney Hills
Honored Contributor

Re: 'find' not finding all files using wildcards

Hi Ron,

Sometimes if I am not sure on what the find command is doing, I'll send the list of filenames to a tempfile. This way I can review the files find has found.

find . -name '*.htm' -print >/tmp/myfind

(your 2nd and 3rd examples are correct)
After checking the file, I then use xargs to process the files.

cat /tmp/myfind | xargs -n1 gzip

HTH

-- Rod Hills
There be dragons...
harry d brown jr
Honored Contributor
Solution

Re: 'find' not finding all files using wildcards


find . -name "*\.htm"|xargs -i gzip {}

then to unzip:

find . -name "*\.htm\.gz"|xargs -i gunzip {}

live free or die
harry
Live Free or Die
Anil C. Sedha
Trusted Contributor

Re: 'find' not finding all files using wildcards

Ron,

Try this..

find . -name "*.htm" -exec gzip {} \;

Regards,
Anil
If you need to learn, now is the best opportunity
Darrell Allen
Honored Contributor

Re: 'find' not finding all files using wildcards

Hi Ron,

Unless I'm missing something, all but your 1st and 4th examples should work. Is it possible some files are being written / closed after you issue the find command?

Harry's example (using xargs) is more performant though.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Ron Levy
Advisor

Re: 'find' not finding all files using wildcards

Harry's pipe to xargs works perfectly, and also he pointed out that the period (.) needs to be backslashed out. Something that slipped by me in my earlier research. Thanks much!
(It must have been a quantity problem for xargs to solve it so neatly.)

-Ron Levy