Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"complex" find command

Status
Not open for further replies.

illmatic

Technical User
Jun 19, 2006
2
DE
Hi all,

I have to run a complex "find command" but do not get the exactly information I want to.

In fact I want to find all "scripts" located on the systems which contain a specific "path".

I set it up in this way "find / -exec grep 'pattern' {} \;"
but the result shows only the lines where the "pattern" occurs
and not the name of the file/script which does not help me at all.

Maybe there is an additionally parameter in the syntax needed which I just don´t know? Otherwise I think I will have to write a script for this issue.

Thank you so far

Alex
 
Hi,

the reason for this behaviour: grep will not tell you the file name, if there is just 1 file; it will always be just 1 if the file name comes from a find command.

There are two possible workarounds, depending on what exactly you need:

1) if you need the file name, but not the actual result of grep command:
find / -exec grep -l 'pattern' {} \;"

2) if you need the result of grep as well:
find / -exec grep 'pattern' {} \; -exec ls {} \;
You will get first the lines in the file, then the file name.
Changing order of the two execs will not work.

regards
 
Yes,

it seems to be working fine!
Thank you so far.

By the way I used the grep -l option.

Regards

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top