Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Find is unnecessary, use grep -r' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Find is unnecessary, use grep -r
Authored by: fungus on Apr 14, '05 03:58:15PM
You don't need to use find at all in this example. grep -r can recursively search folders all by itself.
grep -r -i -l -q "stuff to find" /path/to/dir_to_search | xargs open
-r recursively search all directories
-i case insensitive searching
-l just list the filenames that match
-q stop searching the file after the first match (faster)

Note: be careful with your search pattern stuff to find as open could launch many many files.
You can also shorten it to:
grep -rilq "stuff to find" /path/to/dir | xargs open

[ Reply to This | # ]
Find is unnecessary, use grep -r
Authored by: lazybone on Apr 14, '05 07:47:46PM

Two reasons why I like the original command better:

1.) Not really valid here since we're talking about OS X here: "grep -r" is not guaranteed to be available on other flavors of unix. So I don't like to rely on it's availability

2.) This one is a major one for me: When filenames contain characters that do funky stuff (international) or need to be escaped (like blanks), xargs will miserably fail, while the original command will still work.



[ Reply to This | # ]
Find is unnecessary, use grep -r
Authored by: kps on Apr 15, '05 07:32:11PM
Tip: instead of find -print | xargs, use find -print0 | xargs -0; then blanks and special characters are not a problem.

[ Reply to This | # ]