FD(1)
hey bestie π welcome to the fd(1) page from the General Commands Manual. this is lowkey iconic, highkey a slay, and iykyk. we're gonna read it together, no cap. β¨
πΈ NAME πΈ
fd β find entries in the filesystem π¦
β¨ SYNOPSIS β¨
fd [-HIEsiaLp0hV] [-d depth] [-t filetype] [-e ext] [-E exclude] [-c
when] [-j num] [-x cmd] [pattern [path...]]
π DESCRIPTION π
okay so fd is a simple, fast and user-friendly alternative to find(1). it's giving find but make it cute and actually usable. π
By default fd uses regular expressions for the pattern. However, this can be changed to use simple glob patterns with the --glob option.
By default fd will exclude hidden files and directories, as well as any files that match gitignore rules or ignore rules in .ignore or .fdignore files.
If you wish to search all files in a specific directory, you can use '' or . as the search pattern, to match all files. Or you can use the --search-path option to specify the path(s) instead of the positional parameter.
Options may be given anywhere on the command line. periodt. β¨
π OPTIONS π
-H,--hiddenβ Include hidden files and directories in the search results (default: hidden files and directories are skipped). The flag can be overridden with--no-hidden.
Ignored files are still excluded unless --no-ignore or --no-ignore-vcs is also used.
-I,--no-ignoreβ Show search results from files and directories that would otherwise be ignored by.gitignore.git/info/exclude- The global gitignore configuration (by default
$HOME/.config/git/ignore) .ignore.fdignore- The global fd ignore file (usually
$HOME/.config/fd/ignore)
The flag can be overridden with --ignore.
-u,--unrestrictedβ Perform an unrestricted search, including ignored and hidden files. This is an alias for--hidden --no-ignore.--no-ignore-vcsβ Show search results from files and directories that would otherwise be ignored by gitignore files including.gitignore,.git/info/exclude, and the global gitignore configuration (core.excludesFilegit setting, which defaults to$HOME/.config/git/ignore). The flag can be overridden with--ignore-vcs.--no-require-gitβ Do not require a git repository to respect gitignores. By default,fdwill only respect global gitignore rules,.gitignorerules and local exclude rules iffddetects that you are searching inside a git repository. This flag allows you to relax this restriction such thatfdwill respect all git related ignore rules regardless of whether youβre searching in a git repository or not. The flag can be overridden with--require-git.--no-ignore-parentβ Show search results from files and directories that would otherwise be ignored by gitignore files in parent directories.-s,--case-sensitiveβ Perform a case-sensitive search. By default,fduses case-insensitive searches, unless the pattern contains an uppercase character (smart case).-i,--ignore-caseβ Perform a case-insensitive search. By default,fduses case-insensitive searches, unless the pattern contains an uppercase character (smart case).-g,--globβ Perform a glob-based search instead of a regular expression search. If combined with the--full-pathoption,**can be used to match multiple path components.--regexβ Perform a regular-expression based search (default). This can be used to override--glob.-F,--fixed-stringsβ Treat the pattern as a literal string instead of a regular expression. Note that this also performs substring comparison. If you want to match on an exact filename, consider using--glob.--andpattern β Add additional required search patterns, all of which must be matched. Multiple additional patterns can be specified. The patterns are regular expressions, unless--globor--fixed-stringsis used.-a,--absolute-pathβ Shows the full path starting from the root as opposed to relative paths. The flag can be overridden with--relative-path.-l,--list-detailsβ Use a detailed listing format likels -l. This is basically an alias for--exec-batch ls -lwith some additionallsoptions. This can be used to see more metadata, to show symlink targets and to achieve a deterministic sort order.-L,--followβ By default,fddoes not descend into symlinked directories. Using this flag, symbolic links are also traversed. The flag can be overridden with--no-follow.-p,--full-pathβ By default, the search pattern is only matched against the filename (or directory name). Using this flag, the pattern is matched against the full path.-0,--print0β Separate search results by the null character (instead of newlines). Useful for piping results toxargs.--max-resultscount β Limit the number of search results to count and quit immediately.-1β Limit the search to a single result and quit immediately. This is an alias for--max-results=1.-q,--quietβ When the flag is present, the program does not print anything and will instead exit with a code of0if there is at least one search result. Otherwise, the exit code will be1. This is mainly for usage in scripts and can be faster than checking for output because the search can be stopped early after the first match.--has-resultscan be used as an alias.--show-errorsβ Enable the display of filesystem errors for situations such as insufficient permissions or dead symlinks.--strip-cwd-prefix [when]β By default, relative paths are prefixed with./when-x/--exec,-X/--exec-batch, or-0/--print0are given, to reduce the risk of a path starting with-being treated as a command line option. Use this flag to change this behavior. If this flag is used without a value, it is equivalent to passing"always". Possible values are:neverβ Never strip the./at the beginning of pathsalwaysβ Always strip the./at the beginning of pathsautoβ Only strip if used with--exec,--exec-batch, or--print0. That is, it resets to the default behavior.
--one-file-system,--mount,--xdevβ By default,fdwill traverse the file system tree as far as other options dictate. With this flag,fdensures that it does not descend into a different file system than the one it started in. Comparable to the-mountor-xdevfilters offind(1).-h,--helpβ Print help information.-V,--versionβ Print version information.-d,--max-depthd β Limit directory traversal to at most d levels of depth. By default, there is no limit on the search depth.--min-depthd β Only show search results starting at the given depth. See also:--max-depthand--exact-depth.--exact-depthd β Only show search results at the exact given depth. This is an alias for--min-depth <depth> --max-depth <depth>.--pruneβ Do not traverse into matching directories.-t,--typefiletype β Filter search by type:f,fileβ regular filesd,dir,directoryβ directoriesl,symlinkβ symbolic linksb,block-deviceβ block devicesc,char-deviceβ character devicess,socketβ socketsp,pipeβ named pipes (FIFOs)x,executableβ executable (files)e,emptyβ empty files or directories
This option can be specified more than once to include multiple file types. Searching for --type file --type symlink will show both regular files as well as symlinks. Note that the executable and empty filters work differently: --type executable implies --type file by default. And --type empty searches for empty files and directories, unless either --type file or --type directory is specified in addition.
Examples:
- Only search for files:
fd --type file β¦
fd -tf β¦
- Find both files and symlinks
fd --type file --type symlink β¦
fd -tf -tl β¦
- Find executable files:
fd --type executable
fd -tx
- Find empty files:
fd --type empty --type file
fd -te -tf
- Find empty directories:
fd --type empty --type directory
fd -te -td
-e,--extensionext β Filter search results by file extension ext. This option can be used repeatedly to allow for multiple possible file extensions.
If you want to search for files without extension, you can use the regex ^[^.]+$ as a normal search pattern.
-E,--excludepattern β Exclude files/directories that match the given glob pattern. This overrides any other ignore logic. Multiple exclude patterns can be specified. Examples:
--exclude '*.pyc'
--exclude node_modules
--ignore-containname β Exclude directories that (directly) contain the given name. This option can be specified multiple times.--ignore-filepath β Add a custom ignore-file in.gitignoreformat. These files have a low precedence.-c,--colorwhen β Declare when to colorize search results:autoβ Colorize output when standard output is connected to terminal (default).neverβ Do not colorize output.alwaysβ Always colorize output.
--hyperlinkβ Specify whether the output should use terminal escape codes to indicate a hyperlink to a file url pointing to the path.
The value can be auto, always, or never.
Currently, the default is "never", and if the option is used without an argument "auto" is used. In the future this may be changed to "auto" and "always".
autoβ Only output hyperlinks if color is also enabled, as a proxy for whether terminal escape codes are acceptable.neverβ Never output hyperlink escapes.alwaysβ Always output hyperlink escapes, regardless of color settings.
-j,--threads numβ how many threads should we use for searching and executing? Bestie, the default is the number of available CPU cores, and honestly that's usually the move. π-S,--size sizeβ filter results by how big the files are. The format is<+-><NUM><UNIT>, and here's the whole decoder ring:+β file size has to be greater than or equal to this-β file size has to be less than or equal to this- if you give neither
+nor-, the file size has to be exactly equal to this, no wiggle room, periodt NUMβ the actual number (like500)UNITβ the unit forNUM. Not case-sensitive, so go off. Allowed values:bβ byteskβ kilobytes (base ten, 10^3 = 1000 bytes)mβ megabytesgβ gigabytestβ terabyteskiβ kibibytes (base two, 2^10 = 1024 bytes)miβ mebibytesgiβ gibibytestiβ tebibytes
--changed-within date|durationβ filter by when the file was last modified. Anything with a modification timestamp greater than the argument gets returned. β¨ The argument can be:- a duration (
10h,1d,35min) - a specific point in time as full RFC3339 format with time zone
- a date or datetime in the local time zone (
YYYY-MM-DDorYYYY-MM-DD HH:MM:SS) - the prefix
@followed by the number of seconds since the Unix epoch (@[0-9]+)
- a duration (
--change-newer-than, --newer or --changed-after can be used as aliases, because apparently one name wasn't enough. π
Examples:
--changed-within 2weeks
--change-newer-than "2018-10-27 10:00:00"
--newer 2018-10-27
--changed-after @1704067200
--changed-before date|durationβ same vibe, opposite direction: files with modification timestamps less than the argument get returned. Argument formats are the exact same as above (duration, full RFC3339 with time zone, local-zone date/datetime asYYYY-MM-DDorYYYY-MM-DD HH:MM:SS, or@plus seconds since the Unix epoch, i.e.@[0-9]+).--change-older-thanor--olderwork as aliases.
Examples:
--changed-before "2018-10-27 10:00:00"
--change-older-than 2weeks
--older @1704067200
-o,--owner [user][:group]β filter files by their user and/or group. Format is[(user|uid)][:(group|gid)]and either side is optional. Wanna exclude instead? Slap a!in front of either side. π«Ά
Examples:
--owner john
--owner :students
--owner "!john:students"
-C,--base-directory pathβ changes the current working directory offdto the path you give it. So search results get shown with respect to that base path. Heads up though: relative paths you pass tofdthrough the positional path argument or the--search-pathoption also get resolved relative to this directory. π--path-separator separatorβ sets the path separator used when printing file paths. The default is the OS-specific one:'/'on Unix,'\'on Windows. πΈ--search-path search-pathβ gives you paths to search as an alternative to the positional path argument. It changes the usage to:
Β΄fd [FLAGS/OPTIONS] --search-path PATH --search-path PATH2 [PATTERN]Β΄
--format fmtβ specify a template string used for printing a line for each file found. π₯
These placeholders get substituted into the string for each file before printing:
{}β path (of the current search result){/}β basename{//}β parent directory{.}β path without file extension{/.}β basename without file extension{{β literal'{'(an escape sequence)}}β literal'}'(an escape sequence)
Notice you can use "{{" and "}}" to escape "{" and "}" respectively, which is especially useful if you need to include the literal text of one of the above placeholders. Iconic, honestly. π
-x,--exec commandβ run a command for each search result, in parallel. (Want it sequential? Use--threads=1.) β‘
Big important thing, bestie: all subsequent positional arguments are considered arguments to the command β not to fd. So it's recommended you put -x/--exec last. Alternatively, you can supply a ';' argument to end the argument list and keep going with more fd options. Most shells require ';' to be escaped: '\;'. This option can be given multiple times, and then all commands run for each file found, in the order they are provided. In that case you must supply a ';' argument for all but the last command. π
If parallelism is enabled, the order commands get executed in is non-deterministic. And even with --threads=1, the order is determined by the operating system and may not be what you expect. So yeah β do not rely on any ordering of the results.
Before running the command, any placeholder patterns in it get replaced with the corresponding values for the current file. Same placeholders as in the --format option.
If no placeholder is present, an implicit "{}" at the end is assumed.
If --print0 is also given, then a null character (\0) will be printed between the output for each found entry. That lets another program easily tell the output for each file apart if the command(s) produce multiple lines. π
Examples:
- find all
*.zipfiles and unzip them:
fd -e zip -x unzip
- find
*.hand*.cppfiles and run"clang-format -i .."for each of them:
fd -e h -e cpp -x clang-format -i
- Convert all
*.jpgfiles to*.pngfiles:
fd -e jpg -x convert {} {.}.png
- Run
statfor each*.txtfile, separated by null characters
fd -0 -e txt -x stat
-X,--exec-batch commandβ run the command once, with all search results as arguments. π
The order of the arguments is non-deterministic and should not be relied upon.
It uses the same placeholders as --format and --exec, but instead of expanding once per command invocation, each argument containing a placeholder is expanded for every file in a batch and passed as separate arguments.
If no placeholder is present, an implicit "{}" at the end is assumed.
Like --exec, subsequent arguments are assumed to be part of the command until either the end of the command arguments or a ';' argument. See above. π
Like --exec, this can be used multiple times, and then each command runs in the order given.
Examples:
- Find all
test_*.pyfiles and open them in your favorite editor:
fd -g 'test_*.py' -X vim
Note that this executes a single "vim" process with all search results as arguments.
- Find all
*.rsfiles and count the lines with"wc -l ...":
fd -e rs -X wc -l
--batch-size sizeβ maximum number of arguments to pass to the command given with-X. If the number of results is greater than the given size, the command given with-Xis run again with the remaining arguments. A batch size of zero means there is no limit (that's the default) β but note that batching might still happen because of OS restrictions on the maximum length of command lines. π
π PATTERN SYNTAX π
The regular expression syntax used by fd is documented here:
https://docs.rs/regex/1.0.0/regex/#syntax
The glob syntax is documented here:
https://docs.rs/globset/#syntax
πΏ ENVIRONMENT πΏ
LS_COLORSβ determines how to colorize search results, seedircolors(1). πNO_COLORβ disables colorized output. (the way that some of y'all hate color... ok)XDG_CONFIG_HOME,HOMEβ used to locate the global ignore file. IfXDG_CONFIG_HOMEis set, use$XDG_CONFIG_HOME/fd/ignore. Otherwise, use$HOME/.config/fd/ignore.
π FILES π
.fdignoreβ this file works similarly to a.gitignorefile anywhere in the searched tree, and specifies patterns that should be excluded from the search. But it's specific tofd, and it will be used even if the--no-ignore-vcsoption is used. π$XDG_CONFIG_HOME/fd/ignoreβ global ignore file. Unless ignore mode is turned off (such as with--no-ignore), ignore entries in this file will be ignored, as if it was an.fdignorefile in the current directory.
β¨ EXAMPLES β¨
Find files and directories that match the pattern 'needle':
$ fd needle
Start a search in a given directory (/var/log):
$ fd nginx /var/log
Find all Python files (all files with the extension .py) in the current directory:
$ fd -e py
Open all search results with vim:
$ fd pattern -X vim
π Tips and Tricks π
- If you add
".git/"to your global ignore file ($XDG_CONFIG_HOME/fd/ignore), then".git"folders will be ignored by default, even when the--hiddenoption is used. π - You can use a shell alias or a wrapper script to pass desired flags to
fdby default. For example, if you don't like the default behavior of respecting gitignore, you can usealias fd="/usr/bin/fd --no-ignore-vcs"in your.bashrcto create an alias forfdthat doesn't ignore git files by default. π¦
π BUGS π
Bugs can be reported on GitHub: https://github.com/sharkdp/fd/issues
π SEE ALSO π
and that's the whole page, bestie!! π«Ά This was FD(1) β the fd manual, and yes the footer on this one was literally just the page name FD(1), so consider this your lil sign-off: go forth and find ur files, no cap. πβ¨πΈ
π¦ where this page comes from
- ubuntu stonking: fd-find 10.4.2-1 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms