From fc3b5fab4cb4f9a20671e17e31126f360b0e941a Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 10 Feb 2016 20:39:30 -0500 Subject: Add a README. --- README.md | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b33464b --- /dev/null +++ b/README.md @@ -0,0 +1,93 @@ +`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 intended to be [compatible](https://github.com/tavianator/bfs/issues/6) with GNU `find`. +If you're not familiar with `find`, have a look at the [GNU find manual](https://www.gnu.org/software/findutils/manual/html_mono/find.html) to get acquainted first. + + +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/needle
+
+ +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. + +
+$ 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 -nohidden` to `find -name '.?*' -prune -o -print`. + + +Pretty +------ + +When `bfs` detects that its output is a terminal, it automatically colors its output with the same colors `ls` uses. +This makes it easier to identify relevant files at a glance. + +![Screenshot](http://i.imgur.com/5V6Sxw5.png) -- cgit v1.2.3