BFS(1)

🌸 NAME 🌸

bfs β€” breadth-first search for your files

okay so this is the bfs(1) page from the General Commands Manual, bestie. It's literally find(1)'s breadth-first bestie, and it's iconic.


✨ SYNOPSIS ✨

The whole command-line vibe is:

bfs [flags...]  [paths...]  [expression...]

flags (-H/-L/-P etc.), paths, and expressions may be freely mixed in any order. no cap, mix them however you want.


πŸ¦‹ DESCRIPTION πŸ¦‹

bfs is the breadth-first version of the UNIX find(1) command.

It supports almost every feature from every major find(1) implementation, so your existing command lines should work as-is. It also adds some features of its own, such as a more forgiving command line parser and some additional options. slay.

Each path specified on the command line is treated as a starting path to search through. If no paths are specified, the current directory (.) is searched by default.

Like find(1), bfs interprets its arguments as a short-circuiting Boolean expression. For example,

bfs \( -name '*.txt' -or -lname '*.txt' \) -and -print

will print all the paths that are either .txt files or symbolic links to .txt files. -and is implied between two consecutive expressions, so this is equivalent:

bfs \( -name '*.txt' -or -lname '*.txt' \) -print

Finally, -print is implied if no actions are specified, so this too is equivalent:

bfs -name '*.txt' -or -lname '*.txt'

Most options that take a numeric argument N will also accept -N or +N. -N means "less than N," and +N means "greater than N." periodt.


πŸ’… FLAGS πŸ’…

These are the little command-line flags that set the whole search vibe:

  • -H β€” follow symbolic links on the command line, but not while searching.
  • -L β€” follow all symbolic links.
  • -P β€” never follow symbolic links (the default).
  • -E β€” use extended regular expressions (same as -regextype posix-extended).
  • -X β€” filter out files with non-xargs(1)-safe names.
  • -d β€” search in post-order (same as -depth).
  • -s β€” visit directory entries in sorted order. The sorting takes place within each directory separately, which makes it different from bfs ... | sort, but still provides a deterministic ordering.
  • -x β€” don't descend into other mount points (same as -xdev).
  • -f PATH β€” treat PATH as a path to search (useful if it begins with a dash).
  • -D FLAG β€” turn on a debugging flag (see -D help).
  • -ON β€” enable optimization level N (default: 3).
    • -O0 β€” disable all optimizations.
    • -O1 β€” basic logical simplifications.
    • -O2 β€” all -O1 optimizations, plus dead code elimination and data flow analysis.
    • -O3 β€” all -O2 optimizations, plus re-order expressions to reduce expected cost.
    • -O4/-Ofast β€” all optimizations, including aggressive optimizations that may alter the observed behavior in corner cases.
  • -S bfs|dfs|ids|eds β€” choose the search strategy.
    • bfs β€” breadth-first search (the default).
    • dfs β€” depth-first search. Uses less memory than breadth-first search, but is typically slower to return relevant results.
    • ids β€” iterative deepening search. Performs repeated depth-first searches with increasing depth limits. This gives results in the same order as breadth-first search, but with the reduced memory consumption of depth-first search. Tends to be very slow in practice, so use it only if you absolutely need breadth-first ordering, but -S bfs consumes too much memory.
    • eds β€” exponential deepening search. A compromise between breadth- and depth-first search, which searches exponentially increasing depth ranges (e.g. 0-1, 1-2, 2-4, 4-8, etc.). Provides many of the benefits of breadth-first search with depth-first's reduced memory consumption. Typically far faster than -S ids.
  • -jN β€” search with N threads in parallel (default: number of CPUs, up to 8).

πŸŽ€ OPERATORS πŸŽ€

Boolean expression time, bestie. This is the main character energy of the whole thing:

  • ( expression ) β€” parentheses are used for grouping expressions together. You'll probably have to write \( expression \) to avoid the parentheses being interpreted by the shell.
  • ! expression, -not expression β€” the "not" operator: returns the negation of the truth value of the expression. You may have to write \! expression to avoid ! being interpreted by the shell.
  • expression expression, expression -a expression, expression -and expression β€” short-circuiting "and" operator: if the left-hand expression is true, returns the right-hand expression; otherwise, returns false.
  • expression -o expression, expression -or expression β€” short-circuiting "or" operator: if the left-hand expression is false, returns the right-hand expression; otherwise, returns true.
  • expression , expression β€” the "comma" operator: evaluates the left-hand expression but discards the result, returning the right-hand expression.

🌈 SPECIAL FORMS 🌈

  • -exclude expression β€” exclude all paths matching the expression from the search. This is more powerful than -prune, because it applies even when the expression wouldn't otherwise be evaluated, due to -depth or -mindepth for example. Exclusions are always applied before other expressions, so it may be least confusing to put them first on the command line.
  • -help, --help β€” print usage information, and exit immediately (without parsing the rest of the command line or processing any files).
  • -version, --version β€” print version information, and exit immediately.

πŸ“ OPTIONS πŸ“

More options, because of course there are. Obsessed.

  • -color, -nocolor β€” turn colors on or off (default: -color if outputting to a terminal, -nocolor otherwise).
  • -daystart β€” measure time relative to the start of today.
  • -depth β€” search in post-order (descendents first).
  • -follow β€” follow all symbolic links (same as -L).
  • -files0-from FILE β€” treat the NUL ('\0')-separated paths in FILE as starting points for the search. Pass -files0-from - to read the paths from standard input.
  • -ignore_readdir_race, -noignore_readdir_race β€” whether to report an error if bfs detects that the file tree is modified during the search (default: -noignore_readdir_race).
  • -maxdepth N, -mindepth N β€” ignore files deeper/shallower than N.
  • -mount β€” exclude mount points entirely from the results.
  • -noerror β€” ignore any errors that occur during traversal.
  • -nohidden β€” exclude hidden files and directories.
  • -noleaf β€” ignored; for compatibility with GNU find.
  • -regextype TYPE β€” use TYPE-flavored regular expressions. The possible types are:
    • posix-basic β€” POSIX basic regular expressions (the default).
    • posix-extended β€” POSIX extended regular expressions.
    • ed β€” like ed(1) (same as posix-basic).
    • emacs β€” like emacs(1).
    • grep β€” like grep(1).
    • sed β€” like sed(1) (same as posix-basic).

See regex(7) for a description of regular expression syntax.

  • -status β€” display a status bar while searching.
  • -unique β€” skip any files that have already been seen. Particularly useful along with -L.
  • -warn, -nowarn β€” turn on or off warnings about the command line.
  • -xdev β€” don't descend into other mount points. Unlike -mount, the mount point itself is still included.

πŸ’… TESTS πŸ’…

okay bestie, these are the test filters β€” the vibe check every file has to pass. πŸ’–

  • -acl β€” matches files with a non-trivial Access Control List (acl(5)).
  • -amin [-+]N β€” matches files accessed N minutes ago.
  • -Bmin [-+]N β€” matches files Birthed N minutes ago.
  • -cmin [-+]N β€” matches files changed N minutes ago.
  • -mmin [-+]N β€” matches files modified N minutes ago.
  • -anewer FILE β€” matches files accessed more recently than FILE was modified.
  • -Bnewer FILE β€” matches files Birthed more recently than FILE was modified.
  • -cnewer FILE β€” matches files changed more recently than FILE was modified.
  • -mnewer FILE β€” matches files modified more recently than FILE was modified.
  • -asince TIME β€” matches files accessed more recently than the ISO 8601-style timestamp TIME. Peep -newerXY for examples of the timestamp format.
  • -Bsince TIME β€” matches files Birthed more recently than the ISO 8601-style timestamp TIME. Peep -newerXY for examples of the timestamp format.
  • -csince TIME β€” matches files changed more recently than the ISO 8601-style timestamp TIME. Peep -newerXY for examples of the timestamp format.
  • -msince TIME β€” matches files modified more recently than the ISO 8601-style timestamp TIME. Peep -newerXY for examples of the timestamp format.
  • -atime [-+]N β€” matches files accessed N days ago.
  • -Btime [-+]N β€” matches files Birthed N days ago.
  • -ctime [-+]N β€” matches files changed N days ago.
  • -mtime [-+]N β€” matches files modified N days ago.
  • -capable β€” matches files with POSIX.1e capabilities(7) set.
  • -context GLOB β€” matches files whose SELinux context matches the GLOB.
  • -depth [-+]N β€” matches files with depth N.
  • -empty β€” matches empty files/directories.
  • -executable β€” matches files the current user can execute.
  • -readable β€” matches files the current user can read.
  • -writable β€” matches files the current user can write.
  • -false β€” always false.
  • -true β€” always true.
  • -flags [-+]FLAGS β€” matches files with matching inode FLAGS.
  • -fstype TYPE β€” matches files on file systems with the given TYPE.
  • -gid [-+]N β€” matches files owned by group ID N.
  • -uid [-+]N β€” matches files owned by user ID N.
  • -group NAME β€” matches files owned by the group NAME.
  • -user NAME β€” matches files owned by the user NAME.
  • -hidden β€” matches hidden files (those beginning with .).
  • -ilname GLOB β€” case-insensitive version of -lname.
  • -iname GLOB β€” case-insensitive version of -name.
  • -ipath GLOB β€” case-insensitive version of -path.
  • -iregex REGEX β€” case-insensitive version of -regex.
  • -iwholename GLOB β€” case-insensitive version of -wholename.
  • -inum [-+]N β€” matches files with inode number N.
  • -links [-+]N β€” matches files with N hard links.
  • -lname GLOB β€” matches symbolic links whose target matches the GLOB.
  • -name GLOB β€” matches files whose name matches the GLOB.
  • -newer FILE β€” matches files newer than FILE.
  • -newerXY REFERENCE β€” matches files whose X time is newer than the Y time of REFERENCE. X and Y can be any of [aBcm] (access/Birth/change/modification). Y may also be t to parse REFERENCE as an ISO 8601-style timestamp. For example:
    • 1991-12-14
    • 1991-12-14T03:00
    • 1991-12-14T03:00-07:00
    • '1991-12-14 10:00Z'
  • -nogroup β€” matches files owned by nonexistent groups.
  • -nouser β€” matches files owned by nonexistent users.
  • -path GLOB β€” matches files whose entire path matches the GLOB.
  • -wholename GLOB β€” matches files whose entire path matches the GLOB.
  • -perm [-+/]MODE β€” matches files with a matching mode.
  • -regex REGEX β€” matches files whose entire path matches the regular expression REGEX.
  • -samefile FILE β€” matches hard links to FILE.
  • -since TIME β€” matches files modified since the ISO 8601-style timestamp TIME. Peep -newerXY for examples of the timestamp format.
  • -size [-+]N[cwbkMGTP] β€” matches files with the given size. The unit can be one of
    • chars (1 byte)
    • words (2 bytes)
    • blocks (512 bytes, the default)
    • kiB (1024 bytes)
    • MiB (1024 kiB)
    • GiB (1024 MiB)
    • TiB (1024 GiB)
    • PiB (1024 TiB)
  • -sparse β€” matches files that occupy fewer disk blocks than expected.
  • -type [bcdlpfswD] β€” matches files of the given type. The possible types are
    • block device
    • character device
    • directory
    • link (symbolic)
    • pipe
    • file (regular)
    • socket
    • whiteout
    • Door

Multiple types can be given at once, separated by commas. For example, -type d,f matches both directories and regular files.

  • -used [-+]N β€” matches files last accessed N days after they were changed.
  • -xattr β€” matches files with extended attributes (xattr(7)).
  • -xattrname NAME β€” matches files with the extended attribute NAME.
  • -xtype [bcdlpfswD] β€” matches files of the given type, following links when -type would not, and vice versa.

🎬 ACTIONS 🎬

these are the do-something options, bestie. like, they actually act on the files. πŸ’…

  • -delete β€” deletes any found files (implies -depth). 🚨
  • -rm β€” deletes any found files (implies -depth). 🚨
  • -exec command ... {} ; β€” executes a command.
  • -exec command ... {} + β€” executes a command with multiple files at once.
  • -ok command ... {} ; β€” prompts the user whether to execute a command.
  • -execdir command ... {} ; β€” like -exec/-ok, but runs the command in the same directory as the found file(s).
  • -execdir command ... {} + β€” like -exec/-ok, but runs the command in the same directory as the found file(s).
  • -okdir command ... {} ; β€” like -exec/-ok, but runs the command in the same directory as the found file(s).
  • -exit [STATUS] β€” exits immediately with the given status (0 if unspecified).
  • -fls FILE β€” like -ls, but writes to FILE instead of standard output.
  • -fprint FILE β€” like -print, but writes to FILE instead of standard output.
  • -fprint0 FILE β€” like -print0, but writes to FILE instead of standard output.
  • -fprintf FILE FORMAT β€” like -printf, but writes to FILE instead of standard output.
  • -limit N β€” quits once this action is evaluated N times.
  • -ls β€” lists files like ls -dils.
  • -print β€” prints the path to the found file.
  • -print0 β€” like -print, but uses the null character ('\0') as a separator rather than newlines. Useful in conjunction with xargs -0.
  • -printf FORMAT β€” prints according to a format string (see find(1)). These additional format directives are supported:
    • %w β€” the file's birth time, in the same format as %a/%c/%t.
    • %Wk β€” field k of the file's birth time, in the same format as %Ak/%Ck/%Tk.
  • -printx β€” like -print, but escapes whitespace and quotation characters, to make the output safe for xargs(1). Consider using -print0 and xargs -0 instead.
  • -prune β€” doesn't descend into this directory. This has no effect if -depth is enabled (either explicitly, or implicitly by -delete). Use -exclude instead in that case.
  • -quit β€” quits immediately.

🌱 ENVIRONMENT 🌱

certain environment variables affect the behavior of bfs. yes, bestie, the environment is literally part of the plot. 🌈

  • LANG, LC_* β€” specifies the locale(7) in use for various things. bfs is not (yet) translated to any languages except English, but the locale will still affect the format of printed values. Yes/no prompts (e.g. from -ok) will also be interpreted according to the current locale.
  • LS_COLORS, BFS_COLORS β€” controls the colors used when displaying file paths if -color is enabled. bfs interprets LS_COLORS the same way GNU ls(1) does (see dir_colors(5)). BFS_COLORS can be used to customize bfs without affecting other commands.
  • NO_COLOR β€” causes bfs to default to -nocolor if it is set (see https://no-color.org/).
  • PAGER β€” specifies the pager used for -help output. Defaults to less(1), if found on the current PATH, otherwise more(1).
  • PATH β€” used to resolve executables for -exec[dir] and -ok[dir].
  • POSIXLY_CORRECT β€” makes bfs conform more strictly to the POSIX.1-2017 specification for find(1). Currently this has two effects:
    • Disables warnings by default, because POSIX prohibits writing to standard error (except for the -ok prompt), unless the command also fails with a non-zero exit status.
    • Makes -ls and -fls use 512-byte blocks instead of 1024-byte blocks. (POSIX does not specify these actions, but BSD find(1) implementations use 512-byte blocks, while GNU find(1) uses 1024-byte blocks by default.)

It does not disable bfs's various extensions to the base POSIX functionality. POSIXLY_CORRECT has the same effects on GNU find(1).


🌸 EXAMPLES 🌸

okay, real talk: examples are the main character. here are the exact ones, no cap. πŸ’…

  • bfs β€” with no arguments, bfs prints all files under the current directory in breadth-first order.
  • bfs -name '*.txt' β€” prints all the .txt files under the current directory. *.txt is quoted to ensure the glob is processed by bfs rather than the shell.
  • bfs -name access_log -L /var β€” finds all files named access_log under /var, following symbolic links. bfs allows flags and paths to appear anywhere on the command line.
  • bfs ~ -not -user $USER β€” prints all files in your home directory not owned by you.
  • bfs -xtype l β€” finds broken symbolic links.
  • bfs -name config -exclude -name .git β€” finds all files named config, skipping every .git directory.
  • bfs -type f -executable -exec strip {} + β€” runs strip(1) on all executable files it finds, passing it multiple files at a time.

πŸ’€ BUGS πŸ’€

found a bug? spill: https://github.com/tavianator/bfs/issues


πŸ‘‘ AUTHOR πŸ‘‘


πŸ”Ž SEE ALSO πŸ”Ž


πŸ’– mwah πŸ’‹ β€” that's the wrap, bestie! source/version bfs 4.1.5, date 2026-10-28, manual BFS(1). periodt, go be iconic. 🫢

πŸ“¦ where this page comes from