Best GNU Find Replacement

876 views Asked by At

I'm looking for a better find. The reason is that the find user interface is unintuitive to me (in particular, the pruning / -print style) and difficult to wrap in a function due to strict requirements on argument ordering. locate / updatedb isn't flexible enough to use instead. Would anyone care to share their example find wrappers or find alternatives (command line only, please)?

Here's an example of what I find to be unintuitive usage:

find dir_a dir_b \( -path dir_a/.git -o -path dir_b/out \) -prune -o \( -type f -o -type l \)

Specifying directories before options is strange to me and the syntax for pruning is easily forgotten. (Some programs use a --exclude option instead.) I recognize this is a picky point.

Here's my best attempt at specifying some defaults without losing much functionality:

f()
{
  # The trouble is that -regextype must appear after path but before expression.
  # HACK: "-D debugopts" unsupported and -[HLPO] options assumed to before dirs.
  local a=()
  while [[ -n "$1" ]] && ( [[ ! "${1:0:1}" =~ [-!(),] ]] || [[ "${1:0:2}" =~ -[HLPO] ]] )
  do
    a+=("$1")

    # Eliminate arg from @.
    shift
  done

  find -O3 "${a[@]}" -nowarn -regextype egrep "$@"
}

It seems silly to require a perfect understanding of all options in the program to be able to wrap it up with some defaults and not lose functionality / compatibility with plain find.

I'm guessing I won't fine anything as standard as GNU find, but there might be something better, albeit lesser known.

Update (2013-11-26):

  • At Itay's suggestion, I used ack for about a year. It works very well for at least 95% of my searches.
  • I recently discovered Ag, which is a fast version of ack. It's been working well for the past few weeks.

Update (2014-11-23):

I highly recommend Ag. It works great. There are still many times Find is necessary and for that I continue to seek a nice replacement. Although unquestionably useful, Find's interface is very dated and unnecessarily difficult in my opinion.

Update (2017-08-04):

I now most highly recommend ripgrep as an indispensable Ag replacement. It's a very new tool but it's support for .gitignore files greatly surpasses Ag and in all other ways it is equivalent or better. I continue to search for a Find replacement.

Update (2021-11-28):

I continue to use and love ripgrep which meets most of my needs. For everything else, I use a mixture of find and fd.

1

There are 1 answers

3
Itay Perl On BEST ANSWER

You should try Ack, which is a replacement for both find and grep, optimized for working with source-code trees.