Live data from Hacker News

ffind: a sane replacement for command line file search

wrongsideofmemphis.com

31–40 of 40 posts

Re: ffind: a sane replacement for command line file search

#31
If you just want a shortcut to invoke find in this common way, put this in your shell's profile:

  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
}

Re: ffind: a sane replacement for command line file search

#32
I find myself doing this a lot when sifting through huge codebases:

find . -type f -print0 | xargs -0 grep -Hin

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 ', or more greps to narrow down the result set. Sometimes this all goes in shell scripts or sometimes I just type it all out.

Re: ffind: a sane replacement for command line file search

#33
post #20

Yeah thats ok but holy cow, thanks for letting me find out about ack! ack is awesome!

If you like ack (and who doesn't???), you might like more or less `ag`: https://github.com/ggreer/the_silver_searcher

I did notice ack is pretty slow and i may try ag but speed isnt a problem here for me i think

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"

Re: ffind: a sane replacement for command line file search

#34
post #32

I find myself doing this a lot when sifting through huge codebases: find . -type f -print0 | xargs -0 grep -Hin 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…

How about

  grep -irn  .
?

-r recurses and since it is multiple files implies -H.

Re: ffind: a sane replacement for command line file search

#38
post #6

From reading this, I'm not entirely sure what makes this better than grep. I get why it is cool to have written it.

It's not a replacement for grep, it's a replacement for find

That works by searching the contents of files. So, it is just a grep -l -R . 'search terms', right?

Edit: Actually, now that I am revisiting this thread. The top post hit my misunderstanding on the head.

Re: ffind: a sane replacement for command line file search

#40
post #34
post #32

I find myself doing this a lot when sifting through huge codebases: find . -type f -print0 | xargs -0 grep -Hin 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…

How about grep -irn . ? -r recurses and since it is multiple files implies -H.

Yep, that's much nicer. :) I always forget about recursive grep.
Post reply on HN