A sane replacement for command line file search

Screen Shot 2013-03-26 at 22.53.13
I tend to use the UNIX command line A LOT. I find it very comfortable to work when I am developing and follow the “Unix as IDE” way. The command line is really rich, and you could probably learn a new different command or parameter each day and still be surprised every day for the rest of your life. But there are some things that sticks and gets done, probably not on the most efficient way.

In my case, is using the command `find` to search for files. 95% of the times I use it, is in this form:

find . -name '*some_text*'

Which means ‘find in this directory and all the subdirectories a file that contains some_text in its filename’

It’s not that bad, but I also use a lot ack, which I think is absolutely awesome. I think is a must know for anyone using Unix command line. It is a replacement for grep as a tool for searching code, and works the following way (again, in my 90% usage)

ack some_text

Which means ‘search in all the files that look like code under this directory and subdirectories that contains the text some_text (some_text can be a regex, but usually you can ignore that part)

So, after a couple of tests, I decided to make myself my own ack-inspired find replacement, and called it ffind. I’ve been using it for the last couple of days, and it integrates quite well on my workflow (maybe surprisingly, as I’ve done it with that in mind)

Basically it does this

ffind some_text

Which means ‘find in this directory and all the subdirectories a file that contains some_text in its filename’ (some_text can be a regex). It has also a couple of interesting characteristics like it will ignore hidden directories (starting with a dot), but not hidden files, it will skip directories that the user is not allowed to read due permissions  and the output will have by default the matching text in color.

The other use case is

ffind /dir some_text

Which means ‘find in the directory ‘/dir’ and all the subdirectories a file that contains some_text in its filename’

There are a couple more params, but they are there to deal with special cases.

It is done in Python, and it is available in GitHub. So, if any of this sounds interesting, go there and feel free to use it! Or change it! Or make suggestions!

ffind in Github

ffind in Github

UPDATE: ffind is now available in PyPI.

26 Comments on “ffind

    • I think that grep -R is to search in the content of files, and not in the filenames. I’ve tried to use that command and I haven’t been able to use it to search for a filename (I can be doing something wrong) What is the result you expect for that command?

    • That does the trick, but there are a couple of small differences.

      That script searches also on the whole path, something that is deactivated by default on ffind. This limits the results, as usually, you are only interested in files and main directory, not all the files below.

      Also, that script includes the hidden directories, that again, usually are not interesting when searching.

      Of course, I made ffind for my personal use and it is tailored to my specific workflow and 90% use.

  1. I stopped using ack when I switched from Bash to Zsh – it has recursive wildcards (I heard newer Bash has it too). So I do ‘ls **/*some_text*.py’, or I can press TAB to expand wildcard inline. Builtin Vim grep supports it too: ‘:vimgrep foo **/*.py’.

    Grep is faster than ack.

  2. Surely find . -regex ‘some_text’ is what you were looking for, or a slight wrapper around that?

      • “ag -g” searches for filenames matching a pattern. It’s a good tool, supposed to be fast too.

  3. Would you please upload it to PyPI so we can pip install ffind and start using it right away?

  4. Pingback: ffind is now available on PyPI | Wrong Side of Memphis

  5. But since you seem to like ‘ack’ as tool I would also like to recommend the “-g” option which seems to exactly what this ffind tool is capable of:

    -g REGEX Same as -f, but only print files matching REGEX

    So, looking for a file named ffind.py:

    ack -g “ffind\.py”

    And, you could also restrict ack to look *only* for python-files that includes ffind.py in its name (as the above could, for instance, also return a java-file named “ffind.py.java”):

    ack -g “ffind\.py” –py

  6. Pingback: ffind v0.8 released | Wrong Side of Memphis

  7. Pingback: ffind v1.0.2 released! – Wrong Side of Memphis

  8. Pingback: ffind v1.2.0 released! – Wrong Side of Memphis

  9. Pingback: Notes about ShipItCon 2017 – Wrong Side of Memphis

  10. Pingback: Package and deploy a Python module in PyPI with Poetry, tox and Travis – Wrong Side of Memphis

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: