News for hackers. Stuff that matters.
Re:ffind: a sane replacement for command line file search by silentbicycle on Sunday June 09, 2013 @02:40PM (#5849968)
I wrote a similar tool to this in C, ff (https://github.com/silentbicycle/ff).

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.

Re:ffind: a sane replacement for command line file search by msluyter on Sunday June 09, 2013 @09:37AM (#5848860)
Similarly, I have a little shell function loaded by .zshrc that covers 90% of my use cases:

   findit() {
       find . -name \* -exec grep -iH $1 {} \;
   }
Re:ffind: a sane replacement for command line file search by knome on Sunday June 09, 2013 @12:41PM (#5849510)
Why not just run a recursive grep? That would save having to invoke grep on every single file found.

    findit() {
        grep -iHR $1 .
    }
Alternately, you could use the '+' variant of -exec in order to batch files together to be processed together.
Re:ffind: a sane replacement for command line file search by msluyter on Sunday June 09, 2013 @12:50PM (#5849539)
Cool, I wasn't aware of a -R flag in grep for some reason. I need to go back and re-read the man pages...
Re:ffind: a sane replacement for command line file search by cwp on Sunday June 09, 2013 @12:19PM (#5849420)
Right. There's no need to write a whole new tool just to simplify invocation for common cases. For a guy who uses the command line "a LOT" he's not making good use of his shell.
Re:ffind: a sane replacement for command line file search by ralph on Sunday June 09, 2013 @12:11PM (#5849392)
Is this not equivalent and avoids running grep(1) once for each path?

    find -exec grep -iH ${1?} {} +
Though it still runs grep on directories.
Re:ffind: a sane replacement for command line file search by aarmot on Sunday June 09, 2013 @10:20AM (#5848978)
Author possibly meant something like this (but yeah, same idea) fffind () { find . -regex ".$1."; }
Re:ffind: a sane replacement for command line file search by saidajigumi on Sunday June 09, 2013 @02:28PM (#5849921)
Many of the commenters here have missed an essential line of ffind's description from the article, emphasis mine:

> 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.

Re:ffind: a sane replacement for command line file search by mwfunk on Sunday June 09, 2013 @04:03PM (#5850304)
I find myself doing this a lot when sifting through huge codebases:

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.

Re:ffind: a sane replacement for command line file search by psutor on Sunday June 09, 2013 @05:00PM (#5850581)
How about

  grep -irn <identifier> .
?

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

Re:ffind: a sane replacement for command line file search by mwfunk on Monday June 10, 2013 @06:08PM (#5857674)
Yep, that's much nicer. :) I always forget about recursive grep.
Re:ffind: a sane replacement for command line file search by b0rsuk on Sunday June 09, 2013 @09:49AM (#5848908)
Alternatively, you may just install locate. It won't examine file contents, but it works in the common cases. It's also blazingly fast because it's indexed.
Re:ffind: a sane replacement for command line file search by resiros on Sunday June 09, 2013 @09:53AM (#5848916)
Its problem that you always have to update the index, which can be problematic in fast changing systems (and quite slow in some cases). The greatest disadvantage is that you need root rights to update the index.
Re:ffind: a sane replacement for command line file search by cnvogel on Sunday June 09, 2013 @10:53AM (#5849089)
You can have arbitrary indices being created by arbitrary users. The database(s) that is(are) used by the locate command can be specified by command-line option or by an environment variable.
Re:ffind: a sane replacement for command line file search by sciurus on Sunday June 09, 2013 @03:25PM (#5850128)
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 by resiros on Sunday June 09, 2013 @09:54AM (#5848922)
I looked into his python implementation, I thought he would just translate the parameters and call find, but he instead did go to implement the search algorithm. Wouldn't that make it a bit slower than the original find?
Re:ffind: a sane replacement for command line file search by frontfor on Sunday June 09, 2013 @10:44AM (#5849056)
File system traversal can be quite slow on traditional hard disk drive, it requires a lot of random disk access which has much higher latency than sequential access (think about the moving parts in the disk drive). So I guess that being written in Python is hardly the bottleneck if the disk reads have not been cached by the kernel.
Re:ffind: a sane replacement for command line file search by revscat on Sunday June 09, 2013 @09:28AM (#5848819)
What are the advantages of this over

    mdfind -onlyin . <str>
Re:ffind: a sane replacement for command line file search by keeperofdakeys on Sunday June 09, 2013 @09:41AM (#5848871)
The author probably wanted a simple command, that required as few parameters as needed.
Re:ffind: a sane replacement for command line file search by hollerith on Sunday June 09, 2013 @10:55AM (#5849096)
It searches the contents of files, not just the names of files.
Re:ffind: a sane replacement for command line file search by revscat on Monday June 10, 2013 @09:54AM (#5854308)
So does mdfind.
Re:ffind: a sane replacement for command line file search by hollerith on Monday June 10, 2013 @05:15PM (#5856905)
I stand corrected.

(I tested before I posted, but forgot MD indexing was turned off.)

Re:ffind: a sane replacement for command line file search by dreen on Sunday June 09, 2013 @12:30PM (#5849468)
Yeah thats ok but holy cow, thanks for letting me find out about ack! ack is awesome!
Re:ffind: a sane replacement for command line file search by thezilch on Sunday June 09, 2013 @01:58PM (#5849808)
If you like ack (and who doesn't???), you might like more or less `ag`: https://github.com/ggreer/the_silver_searcher
Re:ffind: a sane replacement for command line file search by dreen on Sunday June 09, 2013 @04:37PM (#5850475)
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 by brown9-2 on Sunday June 09, 2013 @02:08PM (#5849844)
ag is great - so much faster than Ack.
Re:ffind: a sane replacement for command line file search by klibertp on Sunday June 09, 2013 @01:05PM (#5849594)
Try grin if you're biased in favor of Python: https://pypi.python.org/pypi/grin
Re:ffind: a sane replacement for command line file search by neurobashing on Sunday June 09, 2013 @10:15AM (#5848962)
This ffind isn't this ffind: https://github.com/sjl/friendly-find ?
Re:ffind: a sane replacement for command line file search by gcv on Sunday June 09, 2013 @10:50AM (#5849074)
In zsh:

    print -l **/*myfile
Re:ffind: a sane replacement for command line file search by taeric on Sunday June 09, 2013 @09:52AM (#5848914)
From reading this, I'm not entirely sure what makes this better than grep. I get why it is cool to have written it.
Re:ffind: a sane replacement for command line file search by calpaterson on Sunday June 09, 2013 @10:21AM (#5848981)
It's not a replacement for grep, it's a replacement for find
Re:ffind: a sane replacement for command line file search by taeric on Monday June 10, 2013 @12:52PM (#5855564)
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 by falsedan on Sunday June 09, 2013 @06:15PM (#5850928)
It is a remarkable shame the author did not read the ack manpage to discover the '-g' option.
Re:ffind: a sane replacement for command line file search by anonymous on Sunday June 09, 2013 @11:45AM (#5849289)
why not just find|grep <pattern>
Re:ffind: a sane replacement for command line file search by nodata on Sunday June 09, 2013 @02:55PM (#5850024)
find | grep foo