• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

completions/H21-Jan-2022-296216

tests/H03-May-2022-3,2722,832

LICENSEH A D21-Jan-2022674 1310

MakefileH A D21-Jan-20225.8 KiB232159

README.mdH A D21-Jan-20224.5 KiB153110

RELEASES.mdH A D21-Jan-202215.3 KiB596385

bar.cH A D21-Jan-20225.8 KiB249183

bar.hH A D21-Jan-20221.9 KiB588

bfs.1H A D21-Jan-202214.5 KiB802801

bfs.hH A D21-Jan-20221.4 KiB339

bftw.cH A D21-Jan-202235.6 KiB1,5551,040

bftw.hH A D21-Jan-20226.3 KiB22266

color.cH A D21-Jan-202223.5 KiB1,117864

color.hH A D21-Jan-20223.6 KiB12321

ctx.cH A D21-Jan-20226.1 KiB285212

ctx.hH A D21-Jan-20225.4 KiB20257

darray.cH A D21-Jan-20223.2 KiB11370

darray.hH A D21-Jan-20223.5 KiB13413

diag.cH A D21-Jan-20223.1 KiB10574

diag.hH A D21-Jan-20222.7 KiB8720

dir.cH A D21-Jan-20225.8 KiB304252

dir.hH A D21-Jan-20223.1 KiB12529

dstring.cH A D21-Jan-20225.2 KiB221150

dstring.hH A D21-Jan-20224.9 KiB19523

eval.cH A D21-Jan-202234.7 KiB1,6171,135

eval.hH A D21-Jan-20225 KiB11454

exec.cH A D21-Jan-202217.3 KiB683517

exec.hH A D21-Jan-20223.6 KiB12231

expr.hH A D21-Jan-20225 KiB20879

flags.shH A D21-Jan-2022150 127

fsade.cH A D21-Jan-20228.7 KiB393283

fsade.hH A D21-Jan-20222.7 KiB8418

main.cH A D21-Jan-20224.5 KiB14158

mtab.cH A D21-Jan-20225.4 KiB247175

mtab.hH A D21-Jan-20222.3 KiB7210

opt.cH A D21-Jan-202229.7 KiB1,052761

opt.hH A D21-Jan-20221.4 KiB385

parse.cH A D21-Jan-202291.8 KiB3,8172,833

parse.hH A D21-Jan-20221.5 KiB374

printf.cH A D21-Jan-202223.2 KiB926740

printf.hH A D21-Jan-20222.1 KiB6610

pwcache.cH A D21-Jan-20226.6 KiB294227

pwcache.hH A D21-Jan-20223 KiB11815

spawn.cH A D21-Jan-20226.8 KiB319242

spawn.hH A D21-Jan-20223.6 KiB12422

stat.cH A D21-Jan-20229.3 KiB377275

stat.hH A D21-Jan-20224.4 KiB15661

tests.shH A D03-May-202266 KiB3,2342,415

time.cH A D21-Jan-20226.8 KiB324247

time.hH A D21-Jan-20222.6 KiB879

trie.cH A D21-Jan-202218.5 KiB694391

trie.hH A D21-Jan-20224 KiB15723

typo.cH A D21-Jan-20224.6 KiB177142

typo.hH A D21-Jan-20221.5 KiB324

util.cH A D21-Jan-20228.7 KiB485390

util.hH A D03-May-20228.4 KiB324105

README.md

1`bfs`
2=====
3
4[![License](http://img.shields.io/badge/license-0BSD-blue.svg)](https://github.com/tavianator/bfs/blob/main/LICENSE)
5[![Version](https://img.shields.io/github/v/tag/tavianator/bfs?label=version)](https://github.com/tavianator/bfs/releases)
6[![Linux CI Status](https://github.com/tavianator/bfs/actions/workflows/linux.yml/badge.svg?branch=main)](https://github.com/tavianator/bfs/actions/workflows/linux.yml)
7[![macOS CI Status](https://github.com/tavianator/bfs/actions/workflows/macos.yml/badge.svg?branch=main)](https://github.com/tavianator/bfs/actions/workflows/macos.yml)
8[![FreeBSD CI Status](https://github.com/tavianator/bfs/actions/workflows/freebsd.yml/badge.svg?branch=main)](https://github.com/tavianator/bfs/actions/workflows/freebsd.yml)
9
10Breadth-first search for your files.
11
12<img src="https://tavianator.github.io/bfs/animation.svg" alt="Screenshot" />
13
14`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).
15It is otherwise compatible with many versions of `find`, including
16
17- [POSIX `find`](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html)
18- [GNU `find`](https://www.gnu.org/software/findutils/)
19- {[Free](https://www.freebsd.org/cgi/man.cgi?find(1)),[Open](https://man.openbsd.org/find.1),[Net](https://man.netbsd.org/find.1)}BSD `find`
20- [macOS `find`](https://ss64.com/osx/find.html)
21
22If 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.
23
24
25Breadth vs. depth
26-----------------
27
28The advantage of breadth-first over depth first search is that it usually finds the file(s) you're looking for faster.
29Imagine the following directory tree:
30
31<pre>
32haystack
33├── deep
34│   └── 1
35│       └── 2
36│           └── 3
37│               └── 4
38│                   └── ...
39└── shallow
40    └── <strong>needle</strong>
41</pre>
42
43`find` will explore the entire `deep` directory tree before it ever gets to the `shallow` one that contains what you're looking for.
44
45<pre>
46$ <strong>find</strong> haystack
47haystack
48haystack/deep
49haystack/deep/1
50haystack/deep/1/2
51haystack/deep/1/2/3
52haystack/deep/1/2/3/4
53...
54haystack/shallow
55<strong>haystack/shallow/needle</strong>
56</pre>
57
58On the other hand, `bfs` lists files from shallowest to deepest, so you never have to wait for it to explore an entire unrelated subtree.
59
60<pre>
61$ <strong>bfs</strong> haystack
62haystack
63haystack/deep
64haystack/shallow
65haystack/deep/1
66<strong>haystack/shallow/needle</strong>
67haystack/deep/1/2
68haystack/deep/1/2/3
69haystack/deep/1/2/3/4
70...
71</pre>
72
73
74Easy
75----
76
77`bfs` tries to be easier to use than `find`, while remaining compatible.
78For example, `bfs` is less picky about where you put its arguments:
79
80<pre>
81$ <strong>find</strong> -L -name 'needle' <em>haystack</em>
82find: paths must precede expression: haystack
83$ <strong>bfs</strong> -L -name 'needle' <em>haystack</em>
84<strong>haystack/needle</strong>
85
86$ <strong>find</strong> <em>haystack</em> -L -name 'needle'
87find: unknown predicate `-L'
88$ <strong>bfs</strong> <em>haystack</em> -L -name 'needle'
89<strong>haystack/needle</strong>
90
91$ <strong>find</strong> -L <em>haystack</em> -name 'needle'
92<strong>haystack/needle</strong>
93$ <strong>bfs</strong> -L <em>haystack</em> -name 'needle'
94<strong>haystack/needle</strong>
95</pre>
96
97`bfs` also adds some extra options that make some common tasks easier.
98Compare
99
100    bfs -name config -exclude -name .git
101
102vs.
103
104    find ! \( -name .git -prune \) -name config
105
106
107Try it!
108-------
109
110`bfs` may already be packaged for your distribution of choice.
111For example:
112
113<pre>
114<strong>Alpine Linux</strong>
115# apk add bfs
116
117<strong>Debian/Ubuntu</strong>
118# apt install bfs
119
120<strong>NixOS</strong>
121# nix-env -i bfs
122
123<strong>Void Linux</strong>
124# xbps-install -S bfs
125
126<strong>FreeBSD</strong>
127# pkg install bfs
128
129<strong>MacPorts</strong>
130# port install bfs
131
132<strong>Homebrew</strong>
133$ brew install tavianator/tap/bfs
134</pre>
135
136To 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).
137Then run
138
139    $ make
140
141This will build the `bfs` binary in the current directory.
142You can test it out:
143
144    $ ./bfs -nohidden
145
146If you're interested in speed, you may want to build the release version instead:
147
148    $ make release
149
150Finally, if you want to install it globally, run
151
152    $ sudo make install
153