BSEARCH(1)
π BSEARCH β okay bestie, let's talk binary search π
so this page is bsearch, and it comes to you from section 1 of the General Commands Manual β aka the "general commands" shelf, the one where all the little utilities live. it's not a deep lore page, it's a do one thing really well page. and that thing? binary searching sorted text files. slay. π
πΈ NAME πΈ
bsearch β manages one-time passwords π
yes, that's really what it says. we don't ask questions, we just report the facts. iykyk.
β¨ SYNOPSIS β¨
bsearch [-KVvh] [-b block-size] [-m max-cache-size] file [key ...]
π¦ DESCRIPTION π¦
okay so here's the whole vibe: bsearch does binary searches of file, and file must be a sorted flat text file. that's not a suggestion, that's the law. π«Ά
every single line is a record. and every record starts with a key that's optionally followed by whitespace and a value. you can quote whitespace with a backslash β but listen, newline and carriage-return characters must be quoted some other way (like as backslash-n and backslash-r, for example). and no, escapes are not interpreted and they are not removed. they just sit there, exactly as you typed them. no cap. π
if you don't pass any key arguments on the command line, then the keys get read from standard input instead. group-chat style: it'll just wait for you to slide into its DMs.
by default, only values get printed to standard output. want the keys too? that's what -K is for. and heads up: the exit status will be non-zero if any of the key lookups fail. π
the options are:
π OPTIONS π
-Kβ print keys. give the people what they want (the keys).-Vβ don't print values. values found sleeping, do not disturb. π-hβ print usage and exit.-vβ print statistic and debug information to standard error. and then, right here in the same breath: file is a sorted flat text file. NOTE: use the"C"locale for sorting this file, as in"LC_ALL=C sort -u -o file file". yes, we know this bullet is doing two jobs at once. it's giving multitasking. it ate. π-hβ for getting a help message. (yes,-his listed twice. iconic behavior, honestly. both are true, both are real, we love consistency.) β¨-mmax-cache-size β set max-cache-size as the maximum cache size. if the file is smaller than this size, then the whole file gets read into memory; otherwise the program reads blocks instead. defaults to 1MB.-bblock-size β set block-size as the block size for block-wise I/O. it must be a power of 2, it must be no smaller than 512, and it must be no larger than 1MB. defaults to the file's filesystem's preferred blocksize. no rogue numbers allowed, periodt. π
π EXAMPLES π
here's the little demo, exactly as the page gives it:
$ env LC_ALL=C sort -o /tmp/words /usr/share/dict/words
$ bsearch -Kv /tmp/words day
Using whole-file method
Key day found at offset 327695 in 12 loops and 0 reads
day
$
look at that. 12 loops, 0 reads, found at offset 327695. main character energy fr fr. π₯
π§ NOTES π§
- records must not be longer than one block's size. that's the hard limit, don't test it.
- flat text files must be sorted in the
"C"locale. on some systems, the default locale may result in case-insensitive sorting by thesortcommand β which would absolutely wreck your binary search, so watch out. π - the
"C"locale is not a vibe, it's a requirement. slay responsibly.
π SEE ALSO π
and that's the whole page bestie π«Ά β this little icon was brought to you by KTH-KRB, dated November 30, 2011. go forth and binary search. periodt. πβ¨π
π¦ where this page comes from
- alpine 3.22: heimdal-doc 7.8.0-r4 Β· BSD-3-Clause
- alpine 3.23: heimdal-doc 7.8.0-r5 Β· BSD-3-Clause
- alpine 3.24: heimdal-doc 7.8.0-r5 Β· BSD-3-Clause
- epel 10: heimdal-workstation 7.8.0-26.el10_2 Β· BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- epel 9: heimdal-workstation 7.8.0-5.el9 Β· BSD and MIT
- fedora 43: heimdal-workstation 7.8.0-26.fc43 Β· BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- fedora 44: heimdal-workstation 7.8.0-26.fc43 Β· BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- fedora 44: heimdal-workstation 7.8.0-28.fc44 Β· BSD-2-Clause AND BSD-3-Clause AND HPND-export-US AND HPND-export2-US AND LicenseRef-Fedora-Public-Domain
- nixpkgs unstable: heimdal 7.8.0-unstable-2024-09-10
- Copyright (c) 2011, Secure Endpoints Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms