Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash alias query

How can I turn the following command into a bash alias?

find . -name '*.php' | xargs grep --color -n 'search term'

Where I can specify the file extension and 'search term' is obviously the search term :)

So what I want to do is:

 searchFiles 'php' 'search term'

How do I pass the input into the alias? Should I just create a bash script and have the alias point to the script?

like image 430
ae. Avatar asked Nov 25 '09 23:11

ae.


1 Answers

How about using a function? Add this to your .bashrc:

function searchFiles() {
       find . -name \*."$1" -print0 | xargs -0 grep --color -n "$2"
}

and then use it like:

$ searchFiles c include

like image 148
Gonzalo Avatar answered Sep 20 '22 15:09

Gonzalo