LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

bfs

Breadth-first file search

TLDR

Find all files
$ bfs [/path]
copy
Find by name
$ bfs [/path] -name ["*.txt"]
copy
Find only regular files
$ bfs [/path] -type f
copy
Search in parallel with N threads
$ bfs [/path] -j [8] -name ["*.c"]
copy
Exclude a subtree from the search
$ bfs [/path] -exclude -name [node_modules]
copy
Execute command
$ bfs [/path] -name ["*.log"] -delete
copy

SYNOPSIS

bfs [options] [path...] [expression]

DESCRIPTION

bfs is a breadth-first variant of the Unix find command. It traverses directories in breadth-first order rather than depth-first, which can be faster for certain operations and more intuitive when printing results.The tool is compatible with GNU find but uses a different traversal strategy.

PARAMETERS

-name pattern

Match filename pattern
-type type
File type (f, d, l, etc.)
-size n
File size
-mtime n
Modification time
-exec command ;
Execute command
-delete
Delete matched files
-depth
Process directory contents before directory
-maxdepth n
Maximum depth to descend

BFS-SPECIFIC FLAGS

-j n

Search with N threads in parallel (default: number of CPUs, up to 8)
-S bfs|dfs|ids|eds
Select the search strategy: breadth-first (default), depth-first, iterative deepening, or exponential deepening
-color / -nocolor
Turn colors on or off (default: -color when output is a terminal)
-hidden / -nohidden
Include or exclude hidden files (those beginning with .)
-exclude expression
Exclude all paths matching the expression from the search
-unique
Skip files that have already been seen (useful with -L)
-x
Do not descend into other mount points (same as -xdev)
-status
Display a status bar while searching
-files0-from file
Read NUL-separated starting paths from a file
-D flag
Turn on a debugging flag

DIFFERENCES FROM FIND

- Breadth-first traversal order- Generally faster for -quit operations- More intuitive output ordering- Compatible command-line syntax

WORKFLOW

$ # Find all PDFs (breadth-first)
bfs /home -name "*.pdf"

# Find large files in top levels first
bfs / -size +100M

# Delete empty directories
bfs /tmp -type d -empty -delete

# Find recently modified
bfs /var/log -mtime -1
copy

INSTALL

sudo apt install bfs
copy
sudo dnf install bfs
copy
sudo pacman -S bfs
copy
sudo apk add bfs
copy
brew install bfs
copy
nix profile install nixpkgs#bfs
copy

CAVEATS

Less widely available than find. Different traversal order may affect some operations. Not installed by default on most systems. For complex queries, behavior differences possible.

HISTORY

bfs was created by Tavian Barnes in 2015 as an optimized, breadth-first alternative to the traditional find command.

SEE ALSO

find(1), fd(1), locate(1)

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid