|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | 03-May-2022 | - |
| completions/ | H | 21-Jan-2022 | - | 296 | 216 |
| tests/ | H | 03-May-2022 | - | 3,272 | 2,832 |
| LICENSE | H A D | 21-Jan-2022 | 674 | 13 | 10 |
| Makefile | H A D | 21-Jan-2022 | 5.8 KiB | 232 | 159 |
| README.md | H A D | 21-Jan-2022 | 4.5 KiB | 153 | 110 |
| RELEASES.md | H A D | 21-Jan-2022 | 15.3 KiB | 596 | 385 |
| bar.c | H A D | 21-Jan-2022 | 5.8 KiB | 249 | 183 |
| bar.h | H A D | 21-Jan-2022 | 1.9 KiB | 58 | 8 |
| bfs.1 | H A D | 21-Jan-2022 | 14.5 KiB | 802 | 801 |
| bfs.h | H A D | 21-Jan-2022 | 1.4 KiB | 33 | 9 |
| bftw.c | H A D | 21-Jan-2022 | 35.6 KiB | 1,555 | 1,040 |
| bftw.h | H A D | 21-Jan-2022 | 6.3 KiB | 222 | 66 |
| color.c | H A D | 21-Jan-2022 | 23.5 KiB | 1,117 | 864 |
| color.h | H A D | 21-Jan-2022 | 3.6 KiB | 123 | 21 |
| ctx.c | H A D | 21-Jan-2022 | 6.1 KiB | 285 | 212 |
| ctx.h | H A D | 21-Jan-2022 | 5.4 KiB | 202 | 57 |
| darray.c | H A D | 21-Jan-2022 | 3.2 KiB | 113 | 70 |
| darray.h | H A D | 21-Jan-2022 | 3.5 KiB | 134 | 13 |
| diag.c | H A D | 21-Jan-2022 | 3.1 KiB | 105 | 74 |
| diag.h | H A D | 21-Jan-2022 | 2.7 KiB | 87 | 20 |
| dir.c | H A D | 21-Jan-2022 | 5.8 KiB | 304 | 252 |
| dir.h | H A D | 21-Jan-2022 | 3.1 KiB | 125 | 29 |
| dstring.c | H A D | 21-Jan-2022 | 5.2 KiB | 221 | 150 |
| dstring.h | H A D | 21-Jan-2022 | 4.9 KiB | 195 | 23 |
| eval.c | H A D | 21-Jan-2022 | 34.7 KiB | 1,617 | 1,135 |
| eval.h | H A D | 21-Jan-2022 | 5 KiB | 114 | 54 |
| exec.c | H A D | 21-Jan-2022 | 17.3 KiB | 683 | 517 |
| exec.h | H A D | 21-Jan-2022 | 3.6 KiB | 122 | 31 |
| expr.h | H A D | 21-Jan-2022 | 5 KiB | 208 | 79 |
| flags.sh | H A D | 21-Jan-2022 | 150 | 12 | 7 |
| fsade.c | H A D | 21-Jan-2022 | 8.7 KiB | 393 | 283 |
| fsade.h | H A D | 21-Jan-2022 | 2.7 KiB | 84 | 18 |
| main.c | H A D | 21-Jan-2022 | 4.5 KiB | 141 | 58 |
| mtab.c | H A D | 21-Jan-2022 | 5.4 KiB | 247 | 175 |
| mtab.h | H A D | 21-Jan-2022 | 2.3 KiB | 72 | 10 |
| opt.c | H A D | 21-Jan-2022 | 29.7 KiB | 1,052 | 761 |
| opt.h | H A D | 21-Jan-2022 | 1.4 KiB | 38 | 5 |
| parse.c | H A D | 21-Jan-2022 | 91.8 KiB | 3,817 | 2,833 |
| parse.h | H A D | 21-Jan-2022 | 1.5 KiB | 37 | 4 |
| printf.c | H A D | 21-Jan-2022 | 23.2 KiB | 926 | 740 |
| printf.h | H A D | 21-Jan-2022 | 2.1 KiB | 66 | 10 |
| pwcache.c | H A D | 21-Jan-2022 | 6.6 KiB | 294 | 227 |
| pwcache.h | H A D | 21-Jan-2022 | 3 KiB | 118 | 15 |
| spawn.c | H A D | 21-Jan-2022 | 6.8 KiB | 319 | 242 |
| spawn.h | H A D | 21-Jan-2022 | 3.6 KiB | 124 | 22 |
| stat.c | H A D | 21-Jan-2022 | 9.3 KiB | 377 | 275 |
| stat.h | H A D | 21-Jan-2022 | 4.4 KiB | 156 | 61 |
| tests.sh | H A D | 03-May-2022 | 66 KiB | 3,234 | 2,415 |
| time.c | H A D | 21-Jan-2022 | 6.8 KiB | 324 | 247 |
| time.h | H A D | 21-Jan-2022 | 2.6 KiB | 87 | 9 |
| trie.c | H A D | 21-Jan-2022 | 18.5 KiB | 694 | 391 |
| trie.h | H A D | 21-Jan-2022 | 4 KiB | 157 | 23 |
| typo.c | H A D | 21-Jan-2022 | 4.6 KiB | 177 | 142 |
| typo.h | H A D | 21-Jan-2022 | 1.5 KiB | 32 | 4 |
| util.c | H A D | 21-Jan-2022 | 8.7 KiB | 485 | 390 |
| util.h | H A D | 03-May-2022 | 8.4 KiB | 324 | 105 |
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