`bfs` ===== [![License](http://img.shields.io/badge/license-0BSD-blue.svg)](https://github.com/tavianator/bfs/blob/master/LICENSE) [![Version](https://img.shields.io/github/v/tag/tavianator/bfs?label=version)](https://github.com/tavianator/bfs/releases) [![Travis CI Status](https://api.travis-ci.org/tavianator/bfs.svg?branch=master)](https://travis-ci.org/tavianator/bfs) [![Cirrus CI Status](https://api.cirrus-ci.com/github/tavianator/bfs.svg)](https://cirrus-ci.com/github/tavianator/bfs) Breadth-first search for your files. `bfs` is a variant of the UNIX `find` command that operates [breadth-first](https://en.wikipedia.org/wiki/Breadth-first_search) rather than [depth-first](https://en.wikipedia.org/wiki/Depth-first_search). It is otherwise compatible with many versions of `find`, including - [POSIX `find`](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html) - [GNU `find`](https://www.gnu.org/software/findutils/) - {[Free](https://www.freebsd.org/cgi/man.cgi?find(1)),[Open](https://man.openbsd.org/find.1),[Net](http://netbsd.gw.com/cgi-bin/man-cgi?find+1+NetBSD-current)}BSD `find` - [macOS `find`](https://ss64.com/osx/find.html) If you're not familiar with `find`, the [GNU find manual](https://www.gnu.org/software/findutils/manual/html_mono/find.html) provides a good introduction. Breadth vs. depth ----------------- The advantage of breadth-first over depth first search is that it usually finds the file(s) you're looking for faster. Imagine the following directory tree:
haystack ├── deep │ └── 1 │ └── 2 │ └── 3 │ └── 4 │ └── ... └── shallow └── needle`find` will explore the entire `deep` directory tree before it ever gets to the `shallow` one that contains what you're looking for.
$ find haystack haystack haystack/deep haystack/deep/1 haystack/deep/1/2 haystack/deep/1/2/3 haystack/deep/1/2/3/4 ... haystack/shallow haystack/shallow/needleOn the other hand, `bfs` lists files from shallowest to deepest, so you never have to wait for it to explore an entire unrelated subtree.
$ bfs haystack haystack haystack/deep haystack/shallow haystack/deep/1 haystack/shallow/needle haystack/deep/1/2 haystack/deep/1/2/3 haystack/deep/1/2/3/4 ...Easy ---- `bfs` tries to be easier to use than `find`, while remaining compatible. For example, `bfs` is less picky about where you put its arguments:
$ find -L -name 'needle' haystack find: paths must precede expression: haystack $ bfs -L -name 'needle' haystack haystack/needle $ find haystack -L -name 'needle' find: unknown predicate `-L' $ bfs haystack -L -name 'needle' haystack/needle $ find -L haystack -name 'needle' haystack/needle $ bfs -L haystack -name 'needle' haystack/needle`bfs` also adds some extra options that make some common tasks easier. Compare bfs -name config -exclude -name .git` to find ! \( -name .git -prune \) -name config Try it! ------- `bfs` may already be packaged for your distribution of choice. For example:
Alpine Linux # apk add bfs Debian/Ubuntu # apt install bfs NixOS # nix-env -i bfs Void Linux # xbps-install -S bfs FreeBSD # pkg install bfs MacPorts # port install bfs Homebrew $ brew install tavianator/tap/bfsTo install `bfs` from source, download one of the [releases](https://github.com/tavianator/bfs/releases) or clone the [git repo](https://github.com/tavianator/bfs). Then run $ make This will build the `bfs` binary in the current directory. You can test it out: $ ./bfs -nohidden If you're interested in speed, you may want to build the release version instead: $ make clean $ make release Finally, if you want to install it globally, run $ sudo make install