Scroll to navigation

BFS(1) General Commands Manual BFS(1)

NAME

bfs - breadth-first search for your files

SYNOPSIS

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

flags (-H/-L/-P etc.), paths, and expressions may be freely mixed in any order.

DESCRIPTION

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

bfs 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.

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 the 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."

FLAGS

Follow symbolic links on the command line, but not while searching.
Follow all symbolic links.
Never follow symbolic links (the default).
Use extended regular expressions (same as -regextype posix-extended).
Filter out files with non-xargs(1)-safe names.
Search in post-order (same as -depth).
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.
Don't descend into other mount points (same as -xdev).
Treat PATH as a path to search (useful if it begins with a dash).
Turn on a debugging flag (see -D help).

-ON

Enable optimization level N (default: 3).
Disable all optimizations.
Basic logical simplifications.
All -O1 optimizations, plus dead code elimination and data flow analysis.
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.
Breadth-first search (the default).
Depth-first search. Uses less memory than breadth-first search, but is typically slower to return relevant results.
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.
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.

OPERATORS

( 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.
The "comma" operator: evaluates the left-hand expression but discards the result, returning the right-hand expression.

SPECIAL FORMS

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.

OPTIONS

-color
-nocolor

Turn colors on or off (default: -color if outputting to a terminal, -nocolor otherwise).
Measure time relative to the start of today.
Search in post-order (descendents first).
Follow all symbolic links (same as -L).
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.
Don't descend into other mount points (same as -xdev for now, but will skip mount points entirely in the future).
Exclude hidden files and directories.
Ignored; for compatibility with GNU find.
Use TYPE-flavored regexes (default: posix-basic; see -regextype help).
Display a status bar while searching.
Skip any files that have already been seen. Particularly useful along with -L.

-warn
-nowarn

Turn on or off warnings about the command line.
Don't descend into other mount points.

TESTS

Find files with a non-trivial Access Control List (acl(5)).

-amin [-+]N
-Bmin [-+]N
-cmin [-+]N
-mmin [-+]N

Find files accessed/Birthed/changed/modified N minutes ago.

-anewer FILE
-Bnewer FILE
-cnewer FILE
-mnewer FILE

Find files accessed/Birthed/changed/modified more recently than FILE was modified.

-asince TIME
-Bsince TIME
-csince TIME
-msince TIME

Find files accessed/Birthed/changed/modified more recently than the ISO 8601-style timestamp TIME. See -newerXY for examples of the timestamp format.

-atime [-+]N
-Btime [-+]N
-ctime [-+]N
-mtime [-+]N

Find files accessed/Birthed/changed/modified N days ago.
Find files with POSIX.1e capabilities(7) set.
-depth [-+]N
Find files with depth N.
Find empty files/directories.

-executable
-readable
-writable

Find files the current user can execute/read/write.

-false
-true

Always false/true.
Find files on file systems with the given TYPE.

-gid [-+]N
-uid [-+]N

Find files owned by group/user ID N.

-group NAME
-user NAME

Find files owned by the group/user NAME.
Find hidden files (those beginning with .).

-ilname GLOB
-iname GLOB
-ipath GLOB
-iregex REGEX
-iwholename GLOB

Case-insensitive versions of -lname/-name/-path/-regex/-wholename.
Find files with inode number N.
Find files with N hard links.
Find symbolic links whose target matches the GLOB.
Find files whose name matches the GLOB.
Find files newer than FILE.
Find 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-14T10:00Z

-nogroup
-nouser

Find files owned by nonexistent groups/users.

-path GLOB
-wholename GLOB

Find files whose entire path matches the GLOB.
Find files with a matching mode.
Find files whose entire path matches the regular expression REGEX.
Find hard links to FILE.
Find files modified since the ISO 8601-style timestamp TIME. See -newerXY for examples of the timestamp format.
Find files with the given size, in 1-byte characters, 2-byte words, 512-byte blocks (default), or kiB/MiB/GiB/TiB/PiB.
Find files that occupy fewer disk blocks than expected.
Find files of the given type. Possible types are block device, character device, directory, symbolic link, pipe, regular file, socket, whiteout, and Door.
Find files last accessed N days after they were changed.
Find files with extended attributes (xattr(7)).
Find files with the extended attribute NAME.
Find files of the given type, following links when -type would not, and vice versa.

ACTIONS

-delete
-rm

Delete any found files (implies -depth).
Execute a command.
Execute a command with multiple files at once.
Prompt the user whether to execute a command.

-execdir command ... {} ;
-execdir command ... {} +
-okdir command ... {} ;

Like -exec/-ok, but run the command in the same directory as the found file(s).
Exit immediately with the given status (0 if unspecified).

-fls FILE
-fprint FILE
-fprint0 FILE
-fprintf FILE FORMAT

Like -ls/-print/-print0/-printf, but write to FILE instead of standard output.
List files like ls -dils.
Print the path to the found file.
Like -print, but use the null character ('\0') as a separator rather than newlines. Useful in conjunction with xargs -0.
Print 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.
Like -print, but escape whitespace and quotation characters, to make the output safe for xargs(1). Consider using -print0 and xargs -0 instead.
Don't descend into this directory.
Quit immediately.
Print version information.
Print usage information.

ENVIRONMENT

Certain environment variables affect the behavior of bfs.

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.
Causes bfs to default to -nocolor if it is set (see https://no-color.org/).
Specifies the pager used for -help output. Defaults to more(1).
Makes bfs conform more strictly to the POSIX.1-2017 specification for find(1). Currently this just disables warnings by default. It does not disable bfs's various extensions to the base POSIX functionality.

EXAMPLES

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

https://github.com/tavianator/bfs/issues

AUTHOR

Tavian Barnes <tavianator@tavianator.com>

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

SEE ALSO

find(1), locate(1), xargs(1)