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?

1 Answer 1

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
4
  • 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 Commented Mar 28, 2015 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. Commented Mar 28, 2015 at 5:06
  • I'm as root user do I need to use sudo? Commented Mar 28, 2015 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. Commented Mar 28, 2015 at 5:08

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.