summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-03-20 10:44:34 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-03-20 16:40:57 -0400
commit912d2b94cf6ff0871c07325af5ed520a2bc97722 (patch)
treec2a38bcba049dc633811cab5d80f8945a2f91ba8 /docs
parent906009bbb7a88002d0db8b7a26ad9d5b71120869 (diff)
downloadbfs-912d2b94cf6ff0871c07325af5ed520a2bc97722.tar.xz
Implement -limit N
Closes: https://github.com/tavianator/bfs/issues/133
Diffstat (limited to 'docs')
-rw-r--r--docs/USAGE.md34
-rw-r--r--docs/bfs.15
2 files changed, 39 insertions, 0 deletions
diff --git a/docs/USAGE.md b/docs/USAGE.md
index 3efdee0..071c95b 100644
--- a/docs/USAGE.md
+++ b/docs/USAGE.md
@@ -130,6 +130,40 @@ Unlike `-prune`, `-exclude` even works in combination with `-depth`/`-delete`.
---
+### `-limit`
+
+The `-limit N` action makes `bfs` quit once it gets evaluated `N` times.
+Placing it after an action like `-print` limits the number of results that get printed, for example:
+
+```console
+$ bfs -s -type f -name '*.txt'
+./1.txt
+./2.txt
+./3.txt
+./4.txt
+$ bfs -s -type f -name '*.txt' -print -limit 2
+./1.txt
+./2.txt
+```
+
+This is similar to
+
+```console
+$ bfs -s -type f -name '*.txt' | head -n2
+```
+
+but more powerful because you can apply separate limits to different expressions:
+
+```console
+$ bfs \( -name '*.txt' -print -limit 3 -o -name '*.log' -print -limit 4 \) -limit 5
+[At most 3 .txt files, at most 4 .log files, and at most 5 in total]
+```
+
+and more efficient because it will quit immediately.
+When piping to `head`, `bfs` will only quit *after* it tries to output too many results.
+
+---
+
### `-hidden`/`-nohidden`
`-hidden` matches "hidden" files (dotfiles).
diff --git a/docs/bfs.1 b/docs/bfs.1
index 2ecb891..3a4f15a 100644
--- a/docs/bfs.1
+++ b/docs/bfs.1
@@ -725,6 +725,11 @@ but write to
instead of standard output.
.RE
.TP
+\fB\-limit \fIN\fR
+Quit once this action is evaluated
+.I N
+times.
+.TP
.B \-ls
List files like
.B ls