MyGit

tavianator/bfs

Fork: 40 Star: 999 (更新于 2024-12-16 19:41:45)

license: 0BSD

Language: C .

A breadth-first version of the UNIX find command

最后发布版本: 4.0.2 ( 2024-09-18 03:54:04)

官方网址 GitHub网址

bfs
Version License CI Status Code coverage

Features   •   Installation   •   Usage   •   Building   •   Contributing   •   Changelog

Screencast

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

POSIX   •   GNU   •   FreeBSD   •   OpenBSD   •   NetBSD   •   macOS

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.

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. 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.

bfsfind
$ bfs haystack
haystack
haystack/deep
haystack/shallow
haystack/deep/1
haystack/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 tries to be easier to use than find, while remaining compatible.

For example, bfs is less picky about where you put its arguments:

bfsfind
$ bfs -L -name 'needle' haystack
haystack/needle

$ bfs haystack -L -name 'needle'
haystack/needle

$ bfs -L haystack -name 'needle'
haystack/needle
$ find -L -name 'needle' haystack
find: paths must precede expression: haystack

$ find haystack -L -name 'needle'
find: unknown predicate `-L'

$ find -L haystack -name 'needle'
haystack/needle
bfs gives helpful errors and warnings.

For example, bfs will detect and suggest corrections for typos:

$ bfs -nam needle
bfs: error: bfs -nam needle
bfs: error:     ~~~~
bfs: error: Unknown argument; did you mean -name?

bfs also includes a powerful static analysis to help catch mistakes:

$ 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.

For example, the -exclude operator skips over entire subtrees whenever an expression matches. -exclude is both more powerful and easier to use than the standard -prune action; compare

$ bfs -name config -exclude -name .git

to the equivalent

$ find ! \( -name .git -prune \) -name config

As an additional shorthand, -nohidden skips over all hidden files and directories. See the usage documentation for more about the extensions provided by bfs.

Installation

bfs may already be packaged for your operating system.

LinuxmacOS
Alpine Linux
# apk add bfs

Arch Linux
# pacman -S bfs

Debian/Ubuntu
# apt install bfs

Fedora Linux
# dnf install bfs

Gentoo
# emerge sys-apps/bfs

GNU Guix
# guix install bfs

NixOS
# nix-env -i bfs

Void Linux
# xbps-install -S bfs
Homebrew
$ brew install bfs

MacPorts
# port install bfs
BSD
FreeBSD
# pkg install bfs

OpenBSD
# pkg_add bfs
To build bfs from source, you may need to install some dependencies.

The only absolute requirements for building bfs are a C compiler, GNU make, and Bash. These are installed by default on many systems, and easy to install on most others. Refer to your operating system's documentation on building software.

bfs also depends on some system libraries for some of its features. Here's how to install them on some common platforms:

Alpine Linux
# apk add acl{,-dev} attr libcap{,-dev} liburing-dev oniguruma-dev

Arch Linux
# pacman -S acl attr libcap liburing oniguruma

Debian/Ubuntu
# apt install acl libacl1-dev attr libattr1-dev libcap2-bin libcap-dev liburing-dev libonig-dev

Fedora
# dnf install acl libacl-devel attr libcap-devel liburing-devel oniguruma-devel

NixOS
# nix-env -i acl attr libcap liburing oniguruma

Void Linux
# xbps-install -S acl-{devel,progs} attr-progs libcap-{devel,progs} liburing-devel oniguruma-devel

Homebrew
$ brew install oniguruma

MacPorts
# port install oniguruma6

FreeBSD
# pkg install oniguruma

These dependencies are technically optional, though strongly recommended. See the build documentation for how to disable them.

Once you have the dependencies, you can build bfs.

Download one of the releases or clone the git repo. Then run

$ ./configure
$ make

This will build the ./bin/bfs binary. Run the test suite to make sure it works correctly:

$ make check

If you're interested in speed, you may want to build the release version instead:

$ ./configure --enable-release
$ make

Finally, if you want to install it globally, run

# make install

最近版本更新:(数据更新于 2024-10-06 23:05:14)

2024-09-18 03:54:04 4.0.2

2024-08-20 01:07:27 4.0.1

2024-08-16 22:29:20 4.0

2024-06-04 06:37:21 3.3.1

2024-05-29 05:09:26 3.3

2024-05-03 01:20:19 3.2

2024-03-07 08:21:34 3.1.3

2024-03-01 03:21:25 3.1.2

2024-02-16 21:46:33 3.1.1

2024-02-07 05:38:28 3.1

主题(topics):

breadth-first-search, bsd, command-line, directory-tree, filesystem, find, linux, macos, unix

tavianator/bfs同语言 C最近更新仓库

2024-12-21 10:48:05 EdgeTX/edgetx

2024-12-15 21:46:59 arendst/Tasmota

2024-12-13 20:23:33 XITRIX/Moonlight-Switch

2024-12-11 15:17:04 curl/curl

2024-12-07 10:42:25 libsdl-org/SDL

2024-12-05 06:52:52 openwrt/openwrt