6 <a href="https://github.com/tavianator/bfs/releases"><img src="https://img.shields.io/github/v/tag/tavianator/bfs?label=version" alt="Version" align="left"></a>
7 <a href="/LICENSE"><img src="https://img.shields.io/badge/license-0BSD-blue.svg" alt="License" align="left"></a>
8 <a href="https://github.com/tavianator/bfs/actions/workflows/ci.yml"><img src="https://github.com/tavianator/bfs/actions/workflows/ci.yml/badge.svg" alt="CI Status" align="right"></a>
9 <a href="https://codecov.io/gh/tavianator/bfs"><img src="https://img.shields.io/codecov/c/github/tavianator/bfs?token=PpBVuozOVC" alt="Code coverage" align="right"/></a>
12 **[Features] • [Installation] • [Usage] • [Building] • [Hacking] • [Changelog]**
15 [Installation]: #installation
16 [Usage]: /docs/USAGE.md
17 [Building]: /docs/BUILDING.md
18 [Hacking]: /docs/HACKING.md
19 [Changelog]: /docs/CHANGELOG.md
22 <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/tavianator/bfs/gh-pages/animation-dark.svg">
23 <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/tavianator/bfs/gh-pages/animation-light.svg">
24 <img alt="Screencast" src="https://raw.githubusercontent.com/tavianator/bfs/gh-pages/animation-light.svg">
30 `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).
31 It is otherwise compatible with many versions of `find`, including
35 **[POSIX] • [GNU] • [FreeBSD] • [OpenBSD] • [NetBSD] • [macOS]**
37 [POSIX]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html
38 [GNU]: https://www.gnu.org/software/findutils/
39 [FreeBSD]: https://www.freebsd.org/cgi/man.cgi?find(1)
40 [OpenBSD]: https://man.openbsd.org/find.1
41 [NetBSD]: https://man.netbsd.org/find.1
42 [macOS]: https://ss64.com/osx/find.html
46 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.
54 <code>bfs</code> operates breadth-first, which typically finds the file(s) you're looking for faster.
58 Imagine the following directory tree:
69 └── <strong>needle</strong>
72 `find` will explore the entire `deep` directory tree before it ever gets to the `shallow` one that contains what you're looking for.
73 On the other hand, `bfs` lists files from shallowest to deepest, so you never have to wait for it to explore an entire unrelated subtree.
77 <tr><th><code>bfs</code></th><th><code>find</code></th></tr>
79 <td width="506" valign="top">
87 haystack/shallow/needle
92 <td width="506" valign="top">
101 haystack/deep/1/2/3/4
104 haystack/shallow/needle
115 <code>bfs</code> tries to be easier to use than <code>find</code>, while remaining compatible.
119 For example, `bfs` is less picky about where you put its arguments:
123 <tr><th><code>bfs</code></th><th><code>find</code></th></tr>
128 $ bfs -L -name 'needle' haystack
131 $ bfs haystack -L -name 'needle'
134 $ bfs -L haystack -name 'needle'
142 $ find -L -name 'needle' haystack
143 find: paths must precede expression: haystack
145 $ find haystack -L -name 'needle'
146 find: unknown predicate `-L'
148 $ find -L haystack -name 'needle'
160 <code>bfs</code> gives helpful errors and warnings.
164 For example, `bfs` will detect and suggest corrections for typos:
168 bfs: error: bfs -nam needle
170 bfs: error: Unknown argument; did you mean -name?
173 `bfs` also includes a powerful static analysis to help catch mistakes:
176 $ bfs -print -name 'needle'
177 bfs: warning: bfs -print -name needle
178 bfs: warning: ~~~~~~~~~~~~
179 bfs: warning: The result of this expression is ignored.
186 <code>bfs</code> adds some options that make common tasks easier.
190 For example, the `-exclude` operator skips over entire subtrees whenever an expression matches.
191 `-exclude` is both more powerful and easier to use than the standard `-prune` action; compare
194 $ bfs -name config <strong>-exclude -name .git</strong>
200 $ find <strong>! \( -name .git -prune \)</strong> -name config
203 As an additional shorthand, `-nohidden` skips over all hidden files and directories.
204 See the [usage documentation](/docs/USAGE.md#extensions) for more about the extensions provided by `bfs`.
213 <code>bfs</code> may already be packaged for your operating system.
219 <tr><th>Linux</th><th>macOS</th></tr>
222 <td width="506" valign="top" rowspan="3">
225 <strong><a href="https://pkgs.alpinelinux.org/packages?name=bfs">Alpine Linux</a></strong>
228 <strong><a href="https://archlinux.org/packages/extra/x86_64/bfs/">Arch Linux</a></strong>
231 <strong><a href="https://packages.debian.org/sid/bfs">Debian</a>/<a href="https://packages.ubuntu.com/kinetic/bfs">Ubuntu</a></strong>
234 <strong><a href="https://src.fedoraproject.org/rpms/bfs">Fedora Linux</a></strong>
237 <strong><a href="https://packages.guix.gnu.org/packages/bfs/">GNU Guix</a></strong>
240 <strong><a href="https://search.nixos.org/packages?channel=unstable&show=bfs&from=0&size=1&sort=relevance&type=packages&query=bfs">NixOS</a></strong>
243 <strong><a href="https://voidlinux.org/packages/?arch=x86_64&q=bfs">Void Linux</a></strong>
244 # xbps-install -S bfs
248 <td width="506" valign="top">
251 <strong><a href="https://formulae.brew.sh/formula/bfs">Homebrew</a></strong>
254 <strong><a href="https://ports.macports.org/port/bfs/">MacPorts</a></strong>
260 <tr><th height="1">BSD</th></tr>
262 <td width="506" valign="top">
265 <strong><a href="https://www.freshports.org/sysutils/bfs">FreeBSD</a></strong>
268 <strong><a href="https://openports.pl/path/sysutils/bfs">OpenBSD</a></strong>
280 To build <code>bfs</code> from source, you may need to install some dependencies.
284 The only absolute requirements for building `bfs` are a C compiler, [GNU make](https://www.gnu.org/software/make/), and [Bash](https://www.gnu.org/software/bash/).
285 These are installed by default on many systems, and easy to install on most others.
286 Refer to your operating system's documentation on building software.
288 `bfs` also depends on some system libraries for some of its features.
289 Here's how to install them on some common platforms:
292 <strong>Alpine Linux</strong>
293 # apk add acl{,-dev} attr{,-dev} libcap{,-dev} liburing-dev oniguruma-dev
295 <strong>Arch Linux</strong>
296 # pacman -S acl attr libcap liburing oniguruma
298 <strong>Debian/Ubuntu</strong>
299 # apt install acl libacl1-dev attr libattr1-dev libcap2-bin libcap-dev liburing-dev libonig-dev
301 <strong>Fedora</strong>
302 # dnf install acl libacl-devel libattr-devel libcap-devel liburing-devel oniguruma-devel
304 <strong>NixOS</strong>
305 # nix-env -i acl attr libcap liburing oniguruma
307 <strong>Void Linux</strong>
308 # xbps-install -S acl-{devel,progs} attr-{devel,progs} libcap-{devel,progs} liburing-devel oniguruma-devel
310 <strong>Homebrew</strong>
311 $ brew install oniguruma
313 <strong>MacPorts</strong>
314 # port install oniguruma6
316 <strong>FreeBSD</strong>
317 # pkg install oniguruma
320 These dependencies are technically optional, though strongly recommended.
321 See the [build documentation](/docs/BUILDING.md#dependencies) for how to disable them.
326 Once you have the dependencies, you can build <code>bfs</code>.
330 Download one of the [releases](https://github.com/tavianator/bfs/releases) or clone the [git repo](https://github.com/tavianator/bfs).
335 This will build the `./bin/bfs` binary.
336 Run the test suite to make sure it works correctly:
340 If you're interested in speed, you may want to build the release version instead:
344 Finally, if you want to install it globally, run