GithubHelp home page GithubHelp logo

chapmanjacobd / bfs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tavianator/bfs

0.0 2.0 0.0 2.81 MB

A breadth-first version of the UNIX find command

Home Page: https://tavianator.com/projects/bfs.html

License: BSD Zero Clause License

Makefile 1.13% C 82.21% Shell 14.12% Roff 2.54%

bfs's Introduction

bfs

License Version CI Status

Breadth-first search for your files.

Screenshot

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.

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
...
bfs tries to be easier to use than find, while remaining compatible.

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

$ bfs -L -name 'needle' haystack    │ $ find -L -name 'needle' haystack
haystack/needle                     │ find: paths must precede expression: haystack
                                    │
$ bfs haystack -L -name 'needle'    │ $ find haystack -L -name 'needle'
haystack/needle                     │ find: unknown predicate `-L'
                                    │
$ bfs -L haystack -name 'needle'    │ $ find -L haystack -name 'needle'
haystack/needlehaystack/needle
bfs adds some options that make common tasks easier.

-exclude

The -exclude operator skips an entire subtree whenever an expression matches. For example, -exclude -name .git will exclude any files or directories named .git from the search results. -exclude is easier to use than the standard -prune action; compare

bfs -name config -exclude -name .git

to the equivalent

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

Unlike -prune, -exclude even works in combination with -depth/-delete.


-hidden/-nohidden

-hidden matches "hidden" files (dotfiles). bfs -hidden is effectively shorthand for

find \( -name '.*' -not -name . -not -name .. \)

-nohidden is equivalent to -exclude -hidden.


-unique

This option ensures that bfs only visits each file once, even if it's reachable through multiple hard or symbolic links. It's particularly useful when following symbolic links (-L).


-color/-nocolor

When printing to a terminal, bfs automatically colors paths like GNU ls, according to the LS_COLORS environment variable. The -color and -nocolor options override the automatic behavior, which may be handy when you want to preserve colors through a pipe:

bfs -color | less -R

If the NO_COLOR environment variable is set, colors will be disabled by default.

Installation

bfs may already be packaged for your operating system.
Alpine Linux
# apk add bfs

Debian/Ubuntu
# apt 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.

The only absolute requirements for building bfs are a C compiler and GNU make. 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. These dependencies are optional, and can be turned off at build time if necessary by setting the appropriate variable to the empty string (e.g. make WITH_ONIGURUMA=).

Dependency Platforms make flag
acl Linux only WITH_ACL
attr Linux only WITH_ATTR
libcap Linux only WITH_LIBCAP
Oniguruma All WITH_ONIGURUMA

Here's how to install them on some common platforms:

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

NixOS
# nix-env -i acl attr libcap oniguruma

Void Linux
# xbps-install -S acl-devel attr-devel libcap-devel oniguruma-devel

FreeBSD
# pkg install oniguruma

MacPorts
# port install oniguruma6

Homebrew
$ brew install oniguruma

Once the dependencies are installed, download one of the releases or clone the git repo. Then run

$ make

This will build the bfs binary in the current directory. You can test it out:

$ ./bfs -nohidden

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

$ make release

Finally, if you want to install it globally, run

# make install

bfs's People

Contributors

a1346054 avatar bmundt6 avatar data-man avatar lamby avatar lugoues avatar markus-oberhumer avatar rhermes avatar tavianator avatar ylluminarious avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.