Last Updated: February 25, 2016
·
905
· fideloper

Search files for text, get files and line numbers.

Use the find command with grep to find items in your project files.

Here I will search PHP files ('*.php') in my project (current directory as denoted by the period) and print out the file and line number within any file that contains a print_r statement.

$ find . -name '*.php' -print | xargs grep -Hn 'print_r';

Another example: search your computer for .lock files (Good for when your server crashes and breaks Mongo). Use 'sudo' if you don't have privileges to search all files.

$ sudo find / -name '*.lock'

2 Responses
Add your response

Or just, err, you know, use ack.

$ ack --php "print_r"
over 1 year ago ·

@passcod
Yep!

Ack is great as well. One caveat: On Ubuntu, it's ack-grep:

$ sudo apt-get install ack-grep
$ ack-grep --php 'print_r'
over 1 year ago ·