0

I need to search the filesystem for text strings that match some string. I'm trying to get where the commands are used, meaning in which files they are called or used. I need to find every file where any of this text are used: shareEventHandler.php or repToolBroker.phpor loginProctor.php or messageBroker.php or emailBroker.php. How I can do that using grep or find? Can any give me some help?

| improve this question | | | | |
2

Find is used for filenames. Grep is used to search within a file or files. So for this, we'll use grep.

From the root directory you wish to search in, run:

grep -r 'shareEventHandler.php\|repToolBroker.php\|loginProctor.php\|messageBroker.php\|emailBroker.php' .
  • grep - search app
  • -r recursive search from this directory down
  • Use "\|" between search terms
  • "." is used to indicate the current directory

An alternative would be to use RegEx:

grep -rE '((shareEventHandler)|repToolBroker|loginProctor|messageBroker|emailBroker)(\.php)' .
  • -E RegEx flag
| improve this answer | | | | |
  • I've tried from / and get this output have to press CTRL+C to stop the execution of the command. With second one get the same output as before – ReynierPM Mar 28 '15 at 5:02
  • That's normal if you're running a grep or find from /. You can use sudo to avoid the errors, but the errors themselves aren't going to stop the search. – BryanC Mar 28 '15 at 5:06
  • I'm as root user do I need to use sudo? – ReynierPM Mar 28 '15 at 5:07
  • Yes, even as root you'll need to use sudo to avoid those errors. But again, the errors are not going to halt your search. It just fills up your screen with extra garbage results. – BryanC Mar 28 '15 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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