Operating System - HP-UX
1751866 Members
5527 Online
108782 Solutions
New Discussion юеВ

Re: How to find all the file names whose

 
SOLVED
Go to solution
Zhe
Occasional Advisor

How to find all the file names whose

content includes specified string?
i.e. doing grep -l 'string' *
in every directory.


Thanks in advance!
Henry
9 REPLIES 9
ALPER ONEY
Advisor
Solution

Re: How to find all the file names whose

please try the following syntax:
find . -exec grep -l 'string' {} \;

I hope it helps.
Regards
ALPER ONEY
I.S.E TAKASBANK INC
never ever give up.
steven Burgess_2
Honored Contributor

Re: How to find all the file names whose

Hi

find / -name "*string*"

HTH

Steve
take your time and think things through
steven Burgess_2
Honored Contributor

Re: How to find all the file names whose

Whoops

find . -name "*" -exec grep -il 'string' {} \;

HTH

Steve
take your time and think things through
Zhe
Occasional Advisor

Re: How to find all the file names whose

Hello,

Yes, both of you perfectly answered my question. But, still one problem, I wrote like following,
find . -print -exec grep -l 'string' {} \;

why this command could not give me the correct output?

Thanks !
Henry
Joseph Loo
Honored Contributor

Re: How to find all the file names whose

hi,

have u try:

#find . -type f -print |xargs grep -l 'string'

regards.
what you do not see does not mean you should not believe
ALPER ONEY
Advisor

Re: How to find all the file names whose

Dear Zhe,
-print option causes the current path name to be printed. So regardless of grep command, it returns all the file names in the current directory.
Regards
ALPER ONEY
I.S.E TAKASBANK INC

never ever give up.
Zhe
Occasional Advisor

Re: How to find all the file names whose

Hi, ALPER ONEY

I'm almost clear. But,

find . -print -exec rm -r {} \;
works fine, why?

Regards,
Zhe
ALPER ONEY
Advisor

Re: How to find all the file names whose

Hi Zhe,
for your second example, it is ok to take all the file names(no filter) as the parameter of the command rm -r. But for the example including grep command, you need to get file names only including given string.
Because you do not need to filter any files, you second example works.
I hope it helps.
Regards
ALPER ONEY
I.S.E TAKASBANK INC
never ever give up.
Zhe
Occasional Advisor

Re: How to find all the file names whose

Hi, ALPER ONEY

I got it! Thank a lot!

Regards
Zhe