ffind: a sane replacement for command line file search
wrongsideofmemphis.com
wrongsideofmemphis.com
The main difference is that, where `ffind foo` appears to be comparable to
find . -name "*foo*"
, ff is closer to find . -name ".*f.*o.*o.*"
In other words, you don't need an exact match, just the characters given in order. (This is inspired by Lisp-y toolchains where e.g. c-w-c-c would search and expand to call-with-current-continuation.)There are some other features (e.g. '=' toggles literal match, it has smart handling for '/' and directory name grouping), but it's pretty straightforward to use. It also doesn't depend on python.
findit() {
find . -name \* -exec grep -iH $1 {} \;
} findit() {
grep -iHR $1 .
}
Alternately, you could use the '+' variant of -exec in order to batch files together to be processed together. find -exec grep -iH ${1?} {} +
Though it still runs grep on directories.> find in this directory and all the subdirectories a file that contains some_text in its filename
This is NOT a find+grep/ack/ag -alike. It's used for rapid search on filenames, not file contents. Think of it as TextMate's Cmd-T for the command-line.
find . -type f -print0 | xargs -0 grep -Hin <identifier>
The -print0/xargs thing is to get around spaces in filenames or directories. I don't think spaces belong in source files (or directory trees containing source code) for a gazillion different reasons, but I still stumble across it every once in a great while. There are also platforms where system directories have spaces in them, so if you're scrounging through a deep subdirectory tree trying to find something, you may have to deal with the spaces thing. I've been bitten by it enough times that I just always do this rather than have to think about whether or not I might need to do it every time I use find.
Depending on what I'm looking for, I might select files with -type, or a -name glob, or whatever. I use '-type f' most commonly because the source code I deal with has a fair number of interesting things defined outside of files with the standard source/header extensions in their names.
There's usually a couple pipe stages after this filled with 'grep -v <stuff I don't care about>', or more greps to narrow down the result set. Sometimes this all goes in shell scripts or sometimes I just type it all out.
grep -irn <identifier> .
?-r recurses and since it is multiple files implies -H.
function ffind {
if [ $# -eq 1 ]; then
search_path='.'
expression=$1
elif [ $# -eq 2 ]; then
search_path=$1
expression=$2
else
echo "ffind [path] expression"
return 1
fi
find $search_path -name $expression
} mdfind -onlyin . <str>(I tested before I posted, but forgot MD indexing was turned off.)
btw, heres what ive been using up until now:
alias gerp='grep -riHnT . -e'
and more recently: alias gerp="find . -type f | perl -lne 'print if -T;' | xargs egrep -riHnT" print -l **/*myfileEdit: Actually, now that I am revisiting this thread. The top post hit my misunderstanding on the head.