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
Breadth-first search
$ bfs [/path] -type f
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

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

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)

Copied to clipboard
Kai