GitHub - tavianator/bfs: A breadth-first version of the UNIX find command
source link: https://github.com/tavianator/bfs
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
bfs
is a variant of the UNIX find
command that operates breadth-first rather than depth-first.
It is otherwise compatible with many versions of find
, including
If you're not familiar with find
, the GNU find manual provides a good introduction.
Features
bfs
operates breadth-first, which typically finds the file(s) you're looking for faster.
haystack ├── deep │ └── 1 │ └── 2 │ └── 3 │ └── 4 │ └── ... └── shallow └── needle
$ 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
$ 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 ...
bfs
tries to be easier to use than find
, while remaining compatible.
bfs
gives helpful errors and warnings.
$ bfs -nam needle bfs: error: bfs -nam needle bfs: error: ~~~~ bfs: error: Unknown argument; did you mean -name?
$ bfs -print -name 'needle' bfs: warning: bfs -print -name needle bfs: warning: ~~~~~~~~~~~~ bfs: warning: The result of this expression is ignored.
bfs
adds some options that make common tasks easier.
$ bfs -name config -exclude -name .git
$ find ! \( -name .git -prune \) -name config
Installation
bfs
may already be packaged for your operating system.
Alpine Linux # apk add bfs Arch Linux (Available in the AUR) Debian/Ubuntu # apt install bfs Fedora # dnf copr enable xfgusta/bfs # dnf install bfs NixOS # nix-env -i bfs Void Linux # xbps-install -S bfs FreeBSD # pkg install bfs MacPorts # port install bfs Homebrew $ brew install tavianator/tap/bfs
To build bfs
from source, you may need to install some dependencies.
Alpine Linux # apk add acl{,-dev} attr{,-dev} libcap{,-dev} oniguruma-dev Arch Linux # pacman -S acl attr libcap oniguruma Debian/Ubuntu # apt install acl libacl1-dev attr libattr1-dev libcap2-bin libcap-dev libonig-dev Fedora # dnf install libacl-devel libattr-devel libcap-devel oniguruma-devel NixOS # nix-env -i acl attr libcap oniguruma Void Linux # xbps-install -S acl-{devel,progs} attr-{devel,progs} libcap-{devel,progs} oniguruma-devel FreeBSD # pkg install oniguruma MacPorts # port install oniguruma6 Homebrew $ brew install oniguruma
Once you have the dependencies, you can build bfs
.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK