Reputation: 4948
basically, this command does a recursive grep through all files in all sub-directories and I use it ALOT
but it's looooong and takes awhile to type
so I was wondering if instead of...
$ find . -type f -exec grep -l <some word here> {} \;;
that there was a way to alias it or something in my .bashrc so that I could just do something like...
$ findrecursive <some word here>
Upvotes: 3
Views: 2409
Reputation: 2119
For whatever reason, these solutions didn't work for me in LUbuntu using bash in LXTerminal. I added the following to my ~/.bash_aliases
:
function find_helper() { /usr/bin/find . -iname "$@" -readable -prune -print; }
alias find='find_helper'
And I now have the behavior I expected. For example:
find *.xml
Searches recursively from pwd
filtering out the Permission Denied
messages.
Upvotes: 1
Reputation: 4368
I just assume you use Linux and GNU tools, I don't know if it's a GNU extension, but otherwise the snippet below should do what you want, quick and easy:
grep -r <search-regexp>
The above doesn't follow symlinks, if you want your search to do that you need:
grep -R <search-regexp>
In some distros there is an rgrep
command which I just think is an alias to grep -r
. If you don't have it just do alias rgrep="grep -r"
and put it in your .bashrc or equivalent.
Upvotes: 7
Reputation: 18138
Sure. In bash:
function findrecursive() { find . -type f -exec grep -l "$1" {} \;; }
And then call it like this:
findrecursive "hello"
Upvotes: 4
Reputation: 8937
You can always make it into a shell script and put it into one of your bins. For example:
#!/bin/bash
# findrecursive.sh
find . -type f -exec grep -l "$1" {} \;;
Then, after you have made it executable (e.g. chmod
and put in a path directory somewhere (e.g. /bin
) you can call it by saying:
findrecursive.sh <some word here>
Of course you don't need the .sh
extension, it's only a convention for sorting. And you may want to note that the $1 will become <some word here>
when you call the script.
Upvotes: 1