Skip to content
Myr

fd.1

This file

Path

doc/fd.1

588 lines · 19.0 KiB

Last changed by

docs(exec): explain repeated commands for each filePeder Berganbefore adoption5bbfa3e

History of this file

Take it

1.TH FD 12.SH NAME3fd \- find entries in the filesystem4.SH SYNOPSIS5.B fd6.RB [ \-HIEsiaLp0hV ]7.RB [ \-d8.IR depth ]9.RB [ \-t10.IR filetype ]11.RB [ \-e12.IR ext ]13.RB [ \-E14.IR exclude ]15.RB [ \-c16.IR when ]17.RB [ \-j18.IR num ]19.RB [ \-x20.IR cmd ]21.RI [ pattern22.RI [ path... ]]23.SH DESCRIPTION24.B fd25is a simple, fast and user-friendly alternative to26.BR find (1).27.P28By default29.B fd30uses regular expressions for the pattern. However, this can be changed to use simple glob patterns31with the '\-\-glob' option.32.P33By default34.B fd35will exclude hidden files and directories, as well as any files that match gitignore rules36or ignore rules in .ignore or .fdignore files.37.P38If you wish to search all files in a specific directory, you can use '' or . as the search pattern,39to match all files. Or you can use the '\-\-search\-path' option to specify the path(s) instead of40the positional parameter.41.P42Options may be given anywhere on the command line.43.SH OPTIONS44.TP45.B \-H, \-\-hidden46Include hidden files and directories in the search results47(default: hidden files and directories are skipped). The flag can be overridden with '--no-hidden'.48.IP49Ignored files are still excluded unless \-\-no\-ignore or \-\-no\-ignore\-vcs50is also used.51.TP52.B \-I, \-\-no\-ignore53Show search results from files and directories that would otherwise be ignored by54.RS55.IP \[bu] 256.I .gitignore57.IP \[bu]58.I .git/info/exclude59.IP \[bu]60The global gitignore configuration (by default61.IR $HOME/.config/git/ignore )62.IP \[bu]63.I .ignore64.IP \[bu]65.I .fdignore66.IP \[bu]67The global fd ignore file (usually68.I $HOME/.config/fd/ignore69)70.RE71.IP72The flag can be overridden with '--ignore'.73.TP74.B \-u, \-\-unrestricted75Perform an unrestricted search, including ignored and hidden files. This is an alias for '--hidden --no-ignore'.76.TP77.B \-\-no\-ignore\-vcs78Show search results from files and directories that would otherwise be ignored by gitignore files79including80.IR  .gitignore ,81.IR  .git/info/exclude ,82and the global gitignore configuration83.RI ( core.excludesFile84git setting, which defaults to85.IR $HOME/.config/git/ignore ).86The flag can be overridden with '--ignore-vcs'.87.TP88.B \-\-no\-require\-git89Do not require a git repository to respect gitignores. By default, fd will only90respect global gitignore rules, .gitignore rules and local exclude rules if fd91detects that you are searching inside a git repository. This flag allows you to92relax this restriction such that fd will respect all git related ignore rules93regardless of whether you’re searching in a git repository or not. The flag can94be overridden with '--require-git'.95.TP96.B \-\-no\-ignore\-parent97Show search results from files and directories that would otherwise be ignored by gitignore files in98parent directories.99.TP100.B \-s, \-\-case\-sensitive101Perform a case-sensitive search. By default, fd uses case-insensitive searches, unless the102pattern contains an uppercase character (smart case).103.TP104.B \-i, \-\-ignore\-case105Perform a case-insensitive search. By default, fd uses case-insensitive searches, unless the106pattern contains an uppercase character (smart case).107.TP108.B \-g, \-\-glob109Perform a glob-based search instead of a regular expression search.110If combined with the '\-\-full-path' option, '**' can be used to match multiple path components.111.TP112.B \-\-regex113Perform a regular-expression based search (default). This can be used to override --glob.114.TP115.B \-F, \-\-fixed\-strings116Treat the pattern as a literal string instead of a regular expression. Note that this also117performs substring comparison. If you want to match on an exact filename, consider using '\-\-glob'118or '\-\-exact'.119.TP120.B \-\-exact121Perform an exact match. This is equivalent to '\-\-fixed\-strings' but requires the pattern to122match the entire filename (or the full path if '\-\-full\-path' is used), rather than a substring.123Special regex characters in the pattern are treated as literal characters.124Cannot be used together with '\-\-glob' or '\-\-fixed\-strings'.125.TP126.BI "\-\-and " pattern127Add additional required search patterns, all of which must be matched. Multiple additional128patterns can be specified. The patterns are regular expressions, unless '\-\-glob'129or '\-\-fixed\-strings' is used.130.TP131.B \-a, \-\-absolute\-path132Shows the full path starting from the root as opposed to relative paths.133The flag can be overridden with '--relative-path'.134.TP135.B \-l, \-\-list\-details136Use a detailed listing format like 'ls -l'. This is basically an alias137for '--exec-batch ls -l' with some additional 'ls' options. This can be used138to see more metadata, to show symlink targets and to achieve a deterministic139sort order.140.TP141.B \-L, \-\-follow142By default, fd does not descend into symlinked directories. Using this flag, symbolic links are143also traversed. The flag can be overridden with '--no-follow'.144.TP145.B \-p, \-\-full\-path146By default, the search pattern is only matched against the filename (or directory name). Using147this flag, the148.I pattern149is matched against the full path.150.TP151.B \-0, \-\-print0152Separate search results by the null character (instead of newlines). Useful for piping results to153.IR xargs .154.TP155.B \-\-max\-results count156Limit the number of search results to 'count' and quit immediately.157.TP158.B \-1159Limit the search to a single result and quit immediately. This is an alias for '--max-results=1'.160.TP161.B \-q, \-\-quiet162When the flag is present, the program does not print anything and will instead exit with a code of 0 if there is at least one search result.163Otherwise, the exit code will be 1.164This 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.165.B \-\-has\-results166can be used as an alias.167.TP168.B \-\-show-errors169Enable the display of filesystem errors for situations such as insufficient170permissions or dead symlinks.171.TP172.B \-\-strip-cwd-prefix [when]173By default, relative paths are prefixed with './' when -x/--exec,174-X/--exec-batch, or -0/--print0 are given, to reduce the risk of a175path starting with '-' being treated as a command line option. Use176this flag to change this behavior. If this flag is used without a value,177it is equivalent to passing "always". Possible values are:178.RS179.IP never180Never strip the ./ at the beginning of paths181.IP always182Always strip the ./ at the beginning of paths183.IP auto184Only strip if used with --exec, --exec-batch, or --print0. That is, it resets to the default behavior.185.RE186.TP187.B \-\-one\-file\-system, \-\-mount, \-\-xdev188By default, fd will traverse the file system tree as far as other options dictate. With this flag, fd ensures that it does not descend into a different file system than the one it started in. Comparable to the -mount or -xdev filters of find(1).189.TP190.B \-h, \-\-help191Print help information.192.TP193.B \-V, \-\-version194Print version information.195.TP196.BI "\-d, \-\-max\-depth " d197Limit directory traversal to at most198.I d199levels of depth. By default, there is no limit on the search depth.200.TP201.BI "\-\-min\-depth " d202Only show search results starting at the given depth. See also: '--max-depth' and '--exact-depth'.203.TP204.BI "\-\-exact\-depth " d205Only show search results at the exact given depth. This is an alias for '--min-depth <depth> --max-depth <depth>'.206.TP207.B \-\-prune208Do not traverse into matching directories.209.TP210.BI "\-t, \-\-type " filetype211Filter search by type:212.RS213.IP "f, file"214regular files215.IP "d, dir, directory"216directories217.IP "l, symlink"218symbolic links219.IP "b, block-device"220block devices221.IP "c, char-device"222character devices223.IP "s, socket"224sockets225.IP "p, pipe"226named pipes (FIFOs)227.IP "x, executable"228executable (files)229.IP "e, empty"230empty files or directories231.RE232233.RS234This option can be specified more than once to include multiple file types.235Searching for '--type file --type symlink' will show both regular files as well as236symlinks. Note that the 'executable' and 'empty' filters work differently: '--type237executable' implies '--type file' by default. And '--type empty' searches for238empty files and directories, unless either '--type file' or '--type directory' is239specified in addition.240241Examples:242  - Only search for files:243      fd --type file …244      fd -tf …245  - Find both files and symlinks246      fd --type file --type symlink …247      fd -tf -tl …248  - Find executable files:249      fd --type executable250      fd -tx251  - Find empty files:252      fd --type empty --type file253      fd -te -tf254  - Find empty directories:255      fd --type empty --type directory256      fd -te -td257.RE258.TP259.BI "\-e, \-\-extension " ext260Filter search results by extension261.IR ext .262This option can be used repeatedly to allow for multiple possible extensions.263By default, extension filters apply to both files and directories. Use264\fB\-\-type\fR to restrict the search to specific types.265266If you want to search for files without extension, you can use the regex '^[^.]+$'267as a normal search pattern.268.TP269.BI "\-E, \-\-exclude " glob270Exclude files/directories that match the given glob pattern.271This overrides any other ignore logic.272Multiple exclude patterns can be specified.273Examples:274  \-\-exclude '*.pyc'275  \-\-exclude node_modules276.TP277.BI "\-\-ignore-contain " name278Exclude directories that (directly) contain the given name.279This option can be specified multiple times.280.TP281.BI "\-\-ignore-file " path282Add a custom ignore-file in '.gitignore' format.283These files have a low precedence.284.TP285.BI "\-c, \-\-color " when286Declare287.I when288to colorize search results:289.RS290.IP auto291Colorize output when standard output is connected to terminal (default).292.IP never293Do not colorize output.294.IP always295Always colorize output.296.RE297.TP298.B "\-\-hyperlink299Specify whether the output should use terminal escape codes to indicate a hyperlink to a300file url pointing to the path.301302The value can be auto, always, or never.303304Currently, the default is "never", and if the option is used without an argument "auto" is305used. In the future this may be changed to "auto" and "always".306.RS307.IP auto308Only output hyperlinks if color is also enabled, as a proxy for whether terminal escape309codes are acceptable.310.IP never311Never output hyperlink escapes.312.IP always313Always output hyperlink escapes, regardless of color settings.314.RE315.TP316.BI "\-j, \-\-threads " num317Set number of threads to use for searching & executing (default: number of available CPU cores).318.TP319.BI "\-S, \-\-size " size320Limit results based on the size of files using the format321.I <+-><NUM><UNIT>322.RS323.IP '+'324file size must be greater than or equal to this325.IP '-'326file size must be less than or equal to this327.P328If neither '+' nor '-' is specified, file size must be exactly equal to this.329.IP 'NUM'330The numeric size (e.g. 500)331.IP 'UNIT'332The units for NUM. They are not case-sensitive.333Allowed unit values:334.RS335.IP 'b'336bytes337.IP 'k'338kilobytes (base ten, 10^3 = 1000 bytes)339.IP 'm'340megabytes341.IP 'g'342gigabytes343.IP 't'344terabytes345.IP 'ki'346kibibytes (base two, 2^10 = 1024 bytes)347.IP 'mi'348mebibytes349.IP 'gi'350gibibytes351.IP 'ti'352tebibytes353.RE354.RE355.TP356.BI "\-\-changed-within " date|duration357Filter results based on the file modification time.358Files with modification timestamps greater than the argument will be returned.359The argument can be provided as a duration (\fI10h, 1d, 35min\fR) or as a specific point360in time as full RFC3339 format with time zone, as a date or datetime in the361local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR), or as the prefix '@'362followed by the number of seconds since the Unix epoch (@[0-9]+).363\fB\-\-change-newer-than\fR,364.B --newer365or366.B --changed-after367can be used as aliases.368369Examples:370  \-\-changed-within 2weeks371  \-\-change-newer-than "2018-10-27 10:00:00"372  \-\-newer 2018-10-27373  \-\-changed-after @1704067200374.TP375.BI "\-\-changed-before " date|duration376Filter results based on the file modification time.377Files with modification timestamps less than the argument will be returned.378The argument can be provided as a duration (\fI10h, 1d, 35min\fR) or as a specific point379in time as full RFC3339 format with time zone, as a date or datetime in the380local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR), or as the prefix '@'381followed by the number of seconds since the Unix epoch (@[0-9]+).382.B --change-older-than383or384.B --older385can be used as aliases.386387Examples:388  \-\-changed-before "2018-10-27 10:00:00"389  \-\-change-older-than 2weeks390  \-\-older @1704067200391.TP392.BI "-o, \-\-owner " [user][:group]393Filter files by their user and/or group. Format: [(user|uid)][:(group|gid)]. Either side394is optional. Precede either side with a '!' to exclude files instead.395396Examples:397  \-\-owner john398  \-\-owner :students399  \-\-owner "!john:students"400.TP401.BI "-C, \-\-base\-directory " path402Change the current working directory of fd to the provided path. This means that search results will403be shown with respect to the given base path. Note that relative paths which are passed to fd via the404positional \fIpath\fR argument or the \fB\-\-search\-path\fR option will also be resolved relative to405this directory.406.TP407.BI "\-\-path\-separator " separator408Set the path separator to use when printing file paths. The default is the OS-specific separator409('/' on Unix, '\\' on Windows).410.TP411.BI "\-\-search\-path " search\-path412Provide paths to search as an alternative to the positional \fIpath\fR argument. Changes the usage to413\'fd [FLAGS/OPTIONS] \-\-search\-path PATH \-\-search\-path PATH2 [PATTERN]\'414.TP415.BI "\-\-format " fmt416Specify a template string that is used for printing a line for each file found.417418The following placeholders are substituted into the string for each file before printing:419.RS420.IP {}421path (of the current search result)422.IP {/}423basename424.IP {//}425parent directory426.IP {.}427path without file extension428.IP {/.}429basename without file extension430.IP {{431literal '{' (an escape sequence)432.IP }}433literal '}' (an escape sequence)434.P435Notice that you can use "{{" and "}}" to escape "{" and "}" respectively, which is especially436useful if you need to include the literal text of one of the above placeholders.437.RE438.TP439.BI "\-x, \-\-exec " command440.RS441Execute442.I command443for each search result in parallel (use --threads=1 for sequential command execution).444445Note that all subsequent positional arguments are considered to be arguments to the446.I command447- not to fd.448It is therefore recommended to place the \-x/\-\-exec option last. Alternatively, you can supply449a ';' argument to end the argument list and continue with more fd options.450Most shells require ';' to be escaped: '\\;'.451Specify this option multiple times to run several commands for each file or directory found.452For each file or directory, fd runs these commands one after another in the order they appear453on the command line. In that case, you must supply a ';' argument for all but the last command.454When running in parallel, fd buffers command output and prints it together for each search result,455without interleaving it with command output for other results.456457The order in which different search results are processed and their output is printed is not458guaranteed, even with --threads=1.459460Before executing the command, any placeholder patterns in the command are replaced with the461corresponding values for the current file. The same placeholders are used as in the "\-\-format"462option.463464If no placeholder is present, an implicit "{}" at the end is assumed.465466If --print0 is also given, then a null character (\\0) will be printed between the output for each found entry.467This allows another program to easily distinguish the output for each file if the command(s) produce multiple lines.468469Examples:470471  - find all *.zip files and unzip them:472473        fd -e zip -x unzip474475  - find *.h and *.cpp files and run "clang-format -i .." for each of them:476477        fd -e h -e cpp -x clang-format -i478479  - Convert all *.jpg files to *.png files:480481        fd -e jpg -x convert {} {.}.png482483  - Run stat for each *.txt file, separated by null characters484485        fd -0 -e txt -x stat486.RE487.TP488.BI "\-X, \-\-exec-batch " command489.RS490Execute491.I command492once, with all search results as arguments.493494The order of the arguments is non-deterministic and should not be relied upon.495496This uses the same placeholders as "\-\-format" and "\-\-exec", but instead of expanding497once per command invocation each argument containing a placeholder is expanding for every498file in a batch and passed as separate arguments.499500If no placeholder is present, an implicit "{}" at the end is assumed.501502Like \-\-exec, subsequent arguments are assumed to be part of503.I command504until either the end of command arguments or a ';' argument. See above.505506Like \-\-exec, this can be used multiple times, in which case each command will be run in507the order given.508509Examples:510511  - Find all test_*.py files and open them in your favorite editor:512513        fd -g 'test_*.py' -X vim514515    Note that this executes a single "vim" process with all search results as arguments.516517  - Find all *.rs files and count the lines with "wc -l ...":518519        fd -e rs -X wc -l520.RE521.TP522.BI "\-\-batch-size " size523Maximum number of arguments to pass to the command given with -X. If the number of results is524greater than the given size, the command given with -X is run again with remaining arguments. A525batch size of zero means there is no limit (default), but note that batching might still happen526due to OS restrictions on the maximum length of command lines.527.SH PATTERN SYNTAX528The regular expression syntax used by fd is documented here:529530    https://docs.rs/regex/1.0.0/regex/#syntax531532The glob syntax is documented here:533534    https://docs.rs/globset/#syntax535.SH ENVIRONMENT536.TP537.B LS_COLORS538Determines how to colorize search results, see539.BR dircolors (1) .540.TP541.B NO_COLOR542Disables colorized output.543.TP544.B XDG_CONFIG_HOME, HOME545Used to locate the global ignore file. If546.B XDG_CONFIG_HOME547is set, use548.IR $XDG_CONFIG_HOME/fd/ignore .549Otherwise, use550.IR $HOME/.config/fd/ignore .551.SH FILES552.TP553.B .fdignore554This file works similarly to a .gitignore file anywhere in the searched tree and specifies patterns555that should be excluded from the search. However, this file is specific to fd, and will be used even556if the --no-ignore-vcs option is used.557.TP558.B $XDG_CONFIG_HOME/fd/ignore559Global ignore file. Unless ignore mode is turned off (such as with --no-ignore)560ignore entries in this file will be ignored, as if it was an .fdignore file in the561current directory.562.SH EXAMPLES563.TP564.RI "Find files and directories that match the pattern '" needle "':"565$ fd needle566.TP567.RI "Start a search in a given directory (" /var/log "):"568$ fd nginx /var/log569.TP570.RI "Find all Python files (all files with the extension " .py ") in the current directory:"571$ fd -e py572.TP573.RI "Open all search results with vim:"574$ fd pattern -X vim575.SH Tips and Tricks576.IP \[bu]577If you add ".git/" to your global ignore file ($XDG_CONFIG_HOME/fd/ignore), then578".git" folders will be ignored by default, even when the --hidden option is used.579.IP \[bu]580You can use a shell alias or a wrapper script in order to pass desired flags to fd581by default. For example if you do not like the default behavior of respecting gitignore,582you can use583`alias fd="/usr/bin/fd --no-ignore-vcs"`584in your .bashrc to create an alias for fd that doesn't ignore git files by default.585.SH BUGS586Bugs can be reported on GitHub: https://github.com/sharkdp/fd/issues587.SH SEE ALSO588.BR find (1)