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 withnon-xargs(1)-safenames.-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 frombfs ... | 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-O1optimizations, plus dead code elimination and data flow analysis.-O3β all-O2optimizations, 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 bfsconsumes 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 to8).
π 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\! expressionto 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-depthor-mindepthfor 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:-colorif outputting to a terminal,-nocolorotherwise).-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 ifbfsdetects 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:
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 accessedNminutes ago.-Bmin [-+]Nβ matches files BirthedNminutes ago.-cmin [-+]Nβ matches files changedNminutes ago.-mmin [-+]Nβ matches files modifiedNminutes ago.-anewer FILEβ matches files accessed more recently thanFILEwas modified.-Bnewer FILEβ matches files Birthed more recently thanFILEwas modified.-cnewer FILEβ matches files changed more recently thanFILEwas modified.-mnewer FILEβ matches files modified more recently thanFILEwas modified.-asince TIMEβ matches files accessed more recently than the ISO 8601-style timestampTIME. Peep-newerXYfor examples of the timestamp format.-Bsince TIMEβ matches files Birthed more recently than the ISO 8601-style timestampTIME. Peep-newerXYfor examples of the timestamp format.-csince TIMEβ matches files changed more recently than the ISO 8601-style timestampTIME. Peep-newerXYfor examples of the timestamp format.-msince TIMEβ matches files modified more recently than the ISO 8601-style timestampTIME. Peep-newerXYfor examples of the timestamp format.-atime [-+]Nβ matches files accessedNdays ago.-Btime [-+]Nβ matches files BirthedNdays ago.-ctime [-+]Nβ matches files changedNdays ago.-mtime [-+]Nβ matches files modifiedNdays ago.-capableβ matches files with POSIX.1ecapabilities(7)set.-context GLOBβ matches files whose SELinux context matches theGLOB.-depth [-+]Nβ matches files with depthN.-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 inodeFLAGS.-fstype TYPEβ matches files on file systems with the givenTYPE.-gid [-+]Nβ matches files owned by group IDN.-uid [-+]Nβ matches files owned by user IDN.-group NAMEβ matches files owned by the groupNAME.-user NAMEβ matches files owned by the userNAME.-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 numberN.-links [-+]Nβ matches files withNhard links.-lname GLOBβ matches symbolic links whose target matches theGLOB.-name GLOBβ matches files whose name matches theGLOB.-newer FILEβ matches files newer thanFILE.-newerXY REFERENCEβ matches files whoseXtime is newer than theYtime ofREFERENCE.XandYcan be any of[aBcm](access/Birth/change/modification).Ymay also betto parseREFERENCEas an ISO 8601-style timestamp. For example:1991-12-141991-12-14T03:001991-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 theGLOB.-wholename GLOBβ matches files whose entire path matches theGLOB.-perm [-+/]MODEβ matches files with a matching mode.-regex REGEXβ matches files whose entire path matches the regular expressionREGEX.-samefile FILEβ matches hard links toFILE.-since TIMEβ matches files modified since the ISO 8601-style timestampTIME. Peep-newerXYfor examples of the timestamp format.-size [-+]N[cwbkMGTP]β matches files with the given size. The unit can be one ofchars(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 accessedNdays after they were changed.-xattrβ matches files with extended attributes (xattr(7)).-xattrname NAMEβ matches files with the extended attributeNAME.-xtype [bcdlpfswD]β matches files of the given type, following links when-typewould 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 (0if unspecified).-fls FILEβ like-ls, but writes toFILEinstead of standard output.-fprint FILEβ like-print, but writes toFILEinstead of standard output.-fprint0 FILEβ like-print0, but writes toFILEinstead of standard output.-fprintf FILE FORMATβ like-printf, but writes toFILEinstead of standard output.-limit Nβ quits once this action is evaluatedNtimes.-lsβ lists files likels -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 withxargs -0.-printf FORMATβ prints according to a format string (seefind(1)). These additional format directives are supported:%wβ the file's birth time, in the same format as%a/%c/%t.%Wkβ fieldkof 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 forxargs(1). Consider using-print0andxargs -0instead.-pruneβ doesn't descend into this directory. This has no effect if-depthis enabled (either explicitly, or implicitly by-delete). Use-excludeinstead 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 thelocale(7)in use for various things.bfsis 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-coloris enabled.bfsinterpretsLS_COLORSthe same way GNUls(1)does (seedir_colors(5)).BFS_COLORScan be used to customizebfswithout affecting other commands.NO_COLORβ causesbfsto default to-nocolorif it is set (seehttps://no-color.org/).PAGERβ specifies the pager used for-helpoutput. Defaults toless(1), if found on the currentPATH, otherwisemore(1).PATHβ used to resolve executables for-exec[dir]and-ok[dir].POSIXLY_CORRECTβ makesbfsconform more strictly to the POSIX.1-2017 specification forfind(1). Currently this has two effects:- Disables warnings by default, because POSIX prohibits writing to standard error (except for the
-okprompt), unless the command also fails with a non-zero exit status. - Makes
-lsand-flsuse 512-byte blocks instead of 1024-byte blocks. (POSIX does not specify these actions, but BSDfind(1)implementations use 512-byte blocks, while GNUfind(1)uses 1024-byte blocks by default.)
- Disables warnings by default, because POSIX prohibits writing to standard error (except for the
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,bfsprints all files under the current directory in breadth-first order.bfs -name '*.txt'β prints all the.txtfiles under the current directory.*.txtis quoted to ensure the glob is processed bybfsrather than the shell.bfs -name access_log -L /varβ finds all files namedaccess_logunder/var, following symbolic links.bfsallows 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 namedconfig, skipping every.gitdirectory.bfs -type f -executable -exec strip {} +β runsstrip(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 π
Tavian Barnes <tavianator@tavianator.com>β author, icon, legend. πhttps://tavianator.com/projects/bfs.htmlβ project page, slay. β¨
π 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
- arch rolling: bfs 4.1.5-1 Β· 0BSD
- π the page's license: 0BSD
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms