5 <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>
6 <a href="/LICENSE"><img src="https://img.shields.io/badge/license-0BSD-blue.svg" alt="License" align="left"></a>
7 <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>
8 <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>
11 **[Features] • [Installation] • [Usage] • [Building] • [Hacking] • [Changelog]**
14 [Installation]: #installation
15 [Usage]: /docs/USAGE.md
16 [Building]: /docs/BUILDING.md
17 [Hacking]: /docs/HACKING.md
18 [Changelog]: /docs/CHANGELOG.md
21 <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/tavianator/bfs/gh-pages/animation-dark.svg">
22 <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/tavianator/bfs/gh-pages/animation-light.svg">
23 <img alt="Screencast" src="https://raw.githubusercontent.com/tavianator/bfs/gh-pages/animation-light.svg">
29 `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).
30 It is otherwise compatible with many versions of `find`, including
34 **[POSIX] • [GNU] • [FreeBSD] • [OpenBSD] • [NetBSD] • [macOS]**
36 [POSIX]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html
37 [GNU]: https://www.gnu.org/software/findutils/
38 [FreeBSD]: https://www.freebsd.org/cgi/man.cgi?find(1)
39 [OpenBSD]: https://man.openbsd.org/find.1
40 [NetBSD]: https://man.netbsd.org/find.1
41 [macOS]: https://ss64.com/osx/find.html
45 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.
53 <code>bfs</code> operates breadth-first, which typically finds the file(s) you're looking for faster.
57 Imagine the following directory tree:
68 └── <strong>needle</strong>
71 `find` will explore the entire `deep` directory tree before it ever gets to the `shallow` one that contains what you're looking for.
72 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.
76 <tr><th><code>bfs</code></th><th><code>find</code></th></tr>
78 <td width="506" valign="top">
86 haystack/shallow/needle
91 <td width="506" valign="top">
100 haystack/deep/1/2/3/4
103 haystack/shallow/needle
114 <code>bfs</code> tries to be easier to use than <code>find</code>, while remaining compatible.
118 For example, `bfs` is less picky about where you put its arguments:
122 <tr><th><code>bfs</code></th><th><code>find</code></th></tr>
127 $ bfs -L -name 'needle' haystack
130 $ bfs haystack -L -name 'needle'
133 $ bfs -L haystack -name 'needle'
141 $ find -L -name 'needle' haystack
142 find: paths must precede expression: haystack
144 $ find haystack -L -name 'needle'
145 find: unknown predicate `-L'
147 $ find -L haystack -name 'needle'
159 <code>bfs</code> gives helpful errors and warnings.
163 For example, `bfs` will detect and suggest corrections for typos:
167 bfs: error: bfs -nam needle
169 bfs: error: Unknown argument; did you mean -name?
172 `bfs` also includes a powerful static analysis to help catch mistakes:
175 $ bfs -print -name 'needle'
176 bfs: warning: bfs -print -name needle
177 bfs: warning: ~~~~~~~~~~~~
178 bfs: warning: The result of this expression is ignored.
185 <code>bfs</code> adds some options that make common tasks easier.
189 For example, the `-exclude` operator skips over entire subtrees whenever an expression matches.
190 `-exclude` is both more powerful and easier to use than the standard `-prune` action; compare
193 $ bfs -name config <strong>-exclude -name .git</strong>
199 $ find <strong>! \( -name .git -prune \)</strong> -name config
202 As an additional shorthand, `-nohidden` skips over all hidden files and directories.
203 See the [usage documentation](/docs/USAGE.md#extensions) for more about the extensions provided by `bfs`.
212 <code>bfs</code> may already be packaged for your operating system.
218 <tr><th>Linux</th><th>macOS</th></tr>
221 <td width="506" valign="top" rowspan="3">
224 <strong><a href="https://pkgs.alpinelinux.org/packages?name=bfs">Alpine Linux</a></strong>
227 <strong><a href="https://archlinux.org/packages/extra/x86_64/bfs/">Arch Linux</a></strong>
230 <strong><a href="https://packages.debian.org/sid/bfs">Debian</a>/<a href="https://packages.ubuntu.com/kinetic/bfs">Ubuntu</a></strong>
233 <strong><a href="https://src.fedoraproject.org/rpms/bfs">Fedora Linux</a></strong>
236 <strong><a href="https://packages.guix.gnu.org/packages/bfs/">GNU Guix</a></strong>
239 <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>
242 <strong><a href="https://voidlinux.org/packages/?arch=x86_64&q=bfs">Void Linux</a></strong>
243 # xbps-install -S bfs
247 <td width="506" valign="top">
250 <strong><a href="https://formulae.brew.sh/formula/bfs">Homebrew</a></strong>
253 <strong><a href="https://ports.macports.org/port/bfs/">MacPorts</a></strong>
259 <tr><th height="1">BSD</th></tr>
261 <td width="506" valign="top">
264 <strong><a href="https://www.freshports.org/sysutils/bfs">FreeBSD</a></strong>
267 <strong><a href="https://openports.pl/path/sysutils/bfs">OpenBSD</a></strong>
279 To build <code>bfs</code> from source, you may need to install some dependencies.
283 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/).
284 These are installed by default on many systems, and easy to install on most others.
285 Refer to your operating system's documentation on building software.
287 `bfs` also depends on some system libraries for some of its features.
288 Here's how to install them on some common platforms:
291 <strong>Alpine Linux</strong>
292 # apk add acl{,-dev} attr{,-dev} libcap{,-dev} liburing-dev oniguruma-dev
294 <strong>Arch Linux</strong>
295 # pacman -S acl attr libcap liburing oniguruma
297 <strong>Debian/Ubuntu</strong>
298 # apt install acl libacl1-dev attr libattr1-dev libcap2-bin libcap-dev liburing-dev libonig-dev
300 <strong>Fedora</strong>
301 # dnf install acl libacl-devel libattr-devel libcap-devel liburing-devel oniguruma-devel
303 <strong>NixOS</strong>
304 # nix-env -i acl attr libcap liburing oniguruma
306 <strong>Void Linux</strong>
307 # xbps-install -S acl-{devel,progs} attr-{devel,progs} libcap-{devel,progs} liburing-devel oniguruma-devel
309 <strong>Homebrew</strong>
310 $ brew install oniguruma
312 <strong>MacPorts</strong>
313 # port install oniguruma6
315 <strong>FreeBSD</strong>
316 # pkg install oniguruma
319 These dependencies are technically optional, though strongly recommended.
320 See the [build documentation](/docs/BUILDING.md#dependencies) for how to disable them.
325 Once you have the dependencies, you can build <code>bfs</code>.
329 Download one of the [releases](https://github.com/tavianator/bfs/releases) or clone the [git repo](https://github.com/tavianator/bfs).
334 This will build the `./bin/bfs` binary.
335 Run the test suite to make sure it works correctly:
339 If you're interested in speed, you may want to build the release version instead:
343 Finally, if you want to install it globally, run