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?
Add a comment |
1 Answer
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
- 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 beforeReynierPM– ReynierPM2015-03-28 05:02:20 +00:00Commented 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.BryanC– BryanC2015-03-28 05:06:41 +00:00Commented Mar 28, 2015 at 5:06
- I'm as root user do I need to use sudo?ReynierPM– ReynierPM2015-03-28 05:07:16 +00:00Commented 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.BryanC– BryanC2015-03-28 05:08:04 +00:00Commented Mar 28, 2015 at 5:08