README.md
This file
Path
README.md
589 lines · 19.4 KiB · Markdown
Last changed by
Fix a link to ubuntu official pageyuuji.yaginumabefore adoption1b4e1e9
History of this fileTake it
The walk stopped after 200 commits: lines older than 1d16cd8 point at it.
Fix warningssharkdpbefore adoption1d16cd8
lines 1–2why, one step back1# fd2[](https://travis-ci.org/sharkdp/fd)Show `master` build stateDavid Peterbefore adoption8196f79
line 3why, one step back3[](https://ci.appveyor.com/project/sharkdp/fd/branch/master)Fix warningssharkdpbefore adoption1d16cd8
lines 4–5why, one step back4[](https://crates.io/crates/fd-find)5[中文](https://github.com/chinanf-boy/fd-zh)Add link for Koreanspearkkkbefore adoption12bd321
line 6why, one step back6[한국어](https://github.com/spearkkk/fd-kor)Fix warningssharkdpbefore adoption1d16cd8
lines 7–95why, one step back78*fd* is a simple, fast and user-friendly alternative to9[*find*](https://www.gnu.org/software/findutils/).1011While it does not seek to mirror all of *find*'s powerful functionality, it provides sensible12(opinionated) defaults for [80%](https://en.wikipedia.org/wiki/Pareto_principle) of the use cases.1314## Features15* Convenient syntax: `fd PATTERN` instead of `find -iname '*PATTERN*'`.16* Colorized terminal output (similar to *ls*).17* It's *fast* (see [benchmarks](#benchmark) below).18* Smart case: the search is case-insensitive by default. It switches to19 case-sensitive if the pattern contains an uppercase20 character[\*](http://vimdoc.sourceforge.net/htmldoc/options.html#'smartcase').21* Ignores hidden directories and files, by default.22* Ignores patterns from your `.gitignore`, by default.23* Regular expressions.24* Unicode-awareness.25* The command name is *50%* shorter[\*](https://github.com/ggreer/the_silver_searcher) than26 `find` :-).27* Parallel command execution with a syntax similar to GNU Parallel.2829## Demo30313233## Benchmark3435Let's search my home folder for files that end in `[0-9].jpg`. It contains ~190.00036subdirectories and about a million files. For averaging and statistical analysis, I'm using37[hyperfine](https://github.com/sharkdp/hyperfine). The following benchmarks are performed38with a "warm"/pre-filled disk-cache (results for a "cold" disk-cache show the same trends).3940Let's start with `find`:41```42Benchmark #1: find ~ -iregex '.*[0-9]\.jpg$'4344 Time (mean ± σ): 7.236 s ± 0.090 s4546 Range (min … max): 7.133 s … 7.385 s47```4849`find` is much faster if it does not need to perform a regular-expression search:50```51Benchmark #2: find ~ -iname '*[0-9].jpg'5253 Time (mean ± σ): 3.914 s ± 0.027 s5455 Range (min … max): 3.876 s … 3.964 s56```5758Now let's try the same for `fd`. Note that `fd` *always* performs a regular expression59search. The options `--hidden` and `--no-ignore` are needed for a fair comparison,60otherwise `fd` does not have to traverse hidden folders and ignored paths (see below):61```62Benchmark #3: fd -HI '.*[0-9]\.jpg$' ~6364 Time (mean ± σ): 811.6 ms ± 26.9 ms6566 Range (min … max): 786.0 ms … 870.7 ms67```68For this particular example, `fd` is approximately nine times faster than `find -iregex`69and about five times faster than `find -iname`. By the way, both tools found the exact70same 20880 files :smile:.7172Finally, let's run `fd` without `--hidden` and `--no-ignore` (this can lead to different73search results, of course). If *fd* does not have to traverse the hidden and git-ignored74folders, it is almost an order of magnitude faster:75```76Benchmark #4: fd '[0-9]\.jpg$' ~7778 Time (mean ± σ): 123.7 ms ± 6.0 ms7980 Range (min … max): 118.8 ms … 140.0 ms81```8283**Note**: This is *one particular* benchmark on *one particular* machine. While I have84performed quite a lot of different tests (and found consistent results), things might85be different for you! I encourage everyone to try it out on their own. See86[this repository](https://github.com/sharkdp/fd-benchmarks) for all necessary scripts.8788Concerning *fd*'s speed, the main credit goes to the `regex` and `ignore` crates that are also used89in [ripgrep](https://github.com/BurntSushi/ripgrep) (check it out!).9091## Colorized output92`fd` can colorize files by extension, just like `ls`. In order for this to work, the environment93variable [`LS_COLORS`](https://linux.die.net/man/5/dir_colors) has to be set. Typically, the value94of this variable is set by the `dircolors` command which provides a convenient configuration format95to define colors for different file formats.Update LS_COLORS help textDavid Peterbefore adoptione2f90db
lines 96–97why, one step back96On most distributions, `LS_COLORS` should be set already. If you are on Windows or if you are looking97for alternative, more complete (or more colorful) variants, see [here](https://github.com/sharkdp/vivid),Fix warningssharkdpbefore adoption1d16cd8
lines 98–100why, one step back98[here](https://github.com/seebi/dircolors-solarized) or99[here](https://github.com/trapd00r/LS_COLORS).100Update README.mdDavid Peterbefore adoption9c9bb12
line 101why, one step back101`fd` also honors the [`NO_COLOR`](https://no-color.org/) environment variable.honor the NO_COLOR env varDave Parfittbefore adoption70448b0
line 102why, one step back102Fix warningssharkdpbefore adoption1d16cd8
lines 103–132why, one step back103## Parallel command execution104If the `-x`/`--exec` option is specified alongside a command template, a job pool will be created105for executing commands in parallel for each discovered path as the input. The syntax for generating106commands is similar to that of GNU Parallel:107108- `{}`: A placeholder token that will be replaced with the path of the search result109 (`documents/images/party.jpg`).110- `{.}`: Like `{}`, but without the file extension (`documents/images/party`).111- `{/}`: A placeholder that will be replaced by the basename of the search result (`party.jpg`).112- `{//}`: Uses the parent of the discovered path (`documents/images`).113- `{/.}`: Uses the basename, with the extension removed (`party`).114115``` bash116# Convert all jpg files to png files:117fd -e jpg -x convert {} {.}.png118119# Unpack all zip files (if no placeholder is given, the path is appended):120fd -e zip -x unzip121122# Convert all flac files into opus files:123fd -e flac -x ffmpeg -i {} -c:a libopus {.}.opus124125# Count the number of lines in Rust files (the command template can be terminated with ';'):126fd -x wc -l \; -e rs127```128129The number of threads used for command execution can be set with the `--threads`/`-j` option.130131## Installation132Add packaging status to READMEDavid Peterbefore adoptiondb6fc44
lines 133–134why, one step back133[](https://repology.org/project/fd-find/versions)134Fix warningssharkdpbefore adoption1d16cd8
lines 135–138why, one step back135### On Ubuntu136*... and other Debian-based Linux distributions.*137138If you run Ubuntu 19.04 (Disco Dingo) or newer, you can install theFix a link to ubuntu official pageyuuji.yaginumabefore adoption1b4e1e9
line 139why, one step back139[officially maintained package](https://packages.ubuntu.com/fd-find):Fix warningssharkdpbefore adoption1d16cd8
lines 140–149why, one step back140```141sudo apt install fd-find142```143Note that the binary is called `fdfind` as the binary name `fd` is already used by another package.144It is recommended that you add an `alias fd=fdfind` to your shells initialization file, in order to145use `fd` in the same way as in this documentation.146147If you use an older version of Ubuntu, you can download the latest `.deb` package from the148[release page](https://github.com/sharkdp/fd/releases) and install it via:149``` bashPrepare 8.1.0 releasesharkdpbefore adoptiona954944
line 150why, one step back150sudo dpkg -i fd_8.1.0_amd64.deb # adapt version number and architectureFix warningssharkdpbefore adoption1d16cd8
lines 151–213why, one step back151```152153### On Debian154155If you run Debian Buster or newer, you can install the156[officially maintained Debian package](https://tracker.debian.org/pkg/rust-fd-find):157```158sudo apt-get install fd-find159```160Note that the binary is called `fdfind` as the binary name `fd` is already used by another package.161It is recommended that you add an `alias fd=fdfind` to your shells initialization file, in order to162use `fd` in the same way as in this documentation.163164### On Fedora165166Starting with Fedora 28, you can install `fd` from the official package sources:167``` bash168dnf install fd-find169```170171For older versions, you can use this [Fedora copr](https://copr.fedorainfracloud.org/coprs/keefle/fd/) to install `fd`:172``` bash173dnf copr enable keefle/fd174dnf install fd175```176177### On Alpine Linux178179You can install [the fd package](https://pkgs.alpinelinux.org/packages?name=fd)180from the official sources, provided you have the appropriate repository enabled:181```182apk add fd183```184185### On Arch Linux186187You can install [the fd package](https://www.archlinux.org/packages/community/x86_64/fd/) from the official repos:188```189pacman -S fd190```191### On Gentoo Linux192193You can use [the fd ebuild](https://packages.gentoo.org/packages/sys-apps/fd) from the official repo:194```195emerge -av fd196```197198### On openSUSE Linux199200You can install [the fd package](https://software.opensuse.org/package/fd) from the official repo:201```202zypper in fd203```204205### On Void Linux206207You can install `fd` via xbps-install:208```209xbps-install -S fd210```211212### On macOS213Fix homebrew formula linkAdam Smithbefore adoption3c6fab3
line 214why, one step back214You can install `fd` with [Homebrew](https://formulae.brew.sh/formula/fd):Fix warningssharkdpbefore adoption1d16cd8
lines 215–265why, one step back215```216brew install fd217```218219… or with MacPorts:220```221sudo port install fd222```223224### On Windows225226You can download pre-built binaries from the [release page](https://github.com/sharkdp/fd/releases).227228Alternatively, you can install `fd` via [Scoop](http://scoop.sh):229```230scoop install fd231```232233Or via [Chocolatey](https://chocolatey.org):234```235choco install fd236```237238### On NixOS / via Nix239240You can use the [Nix package manager](https://nixos.org/nix/) to install `fd`:241```242nix-env -i fd243```244245### On FreeBSD246247You can install [the fd-find package](https://www.freshports.org/sysutils/fd) from the official repo:248```249pkg install fd-find250```251252### From NPM253254On linux and macOS, you can install the [fd-find](https://npm.im/fd-find) package:255256```257npm install -g fd-find258```259260### From source261262With Rust's package manager [cargo](https://github.com/rust-lang/cargo), you can install *fd* via:263```264cargo install fd-find265```Bump min. required Rust version to 1.36sharkdpbefore adoptiondd07bc9
line 266why, one step back266Note that rust version *1.36.0* or later is required.Fix warningssharkdpbefore adoption1d16cd8
lines 267–292why, one step back267268### From binaries269270The [release page](https://github.com/sharkdp/fd/releases) includes precompiled binaries for Linux, macOS and Windows.271272## Development273```bash274git clone https://github.com/sharkdp/fd275276# Build277cd fd278cargo build279280# Run unit tests and integration tests281cargo test282283# Install284cargo install285```286287## Command-line options288```289USAGE:290 fd [FLAGS/OPTIONS] [<pattern>] [<path>...]291292FLAGS:Update READMEsharkdpbefore adoption2340bab
lines 293–298why, one step back293 -H, --hidden Search hidden files and directories294 -I, --no-ignore Do not respect .(git|fd)ignore files295 -s, --case-sensitive Case-sensitive search (default: smart case)296 -i, --ignore-case Case-insensitive search (default: smart case)297 -g, --glob Glob-based search (default: regular expression)298 -a, --absolute-path Show absolute instead of relative pathsUpdate USAGE sectionsharkdpbefore adoptiona06efe1
line 299why, one step back299 -l, --list-details Use a long listing format with file metadataUpdate READMEsharkdpbefore adoption2340bab
lines 300–304why, one step back300 -L, --follow Follow symbolic links301 -p, --full-path Search full path (default: file-/dirname only)302 -0, --print0 Separate results by the null character303 -h, --help Prints help information304 -V, --version Prints version informationFix warningssharkdpbefore adoption1d16cd8
lines 305–308why, one step back305306OPTIONS:307 -d, --max-depth <depth> Set maximum search depth (default: none)308 -t, --type <filetype>... Filter by type: file (f), directory (d), symlink (l),Update USAGE sectionsharkdpbefore adoptiona06efe1
line 309why, one step back309 executable (x), empty (e), socket (s), pipe (p)Fix warningssharkdpbefore adoption1d16cd8
lines 310–319why, one step back310 -e, --extension <ext>... Filter by file extension311 -x, --exec <cmd> Execute a command for each search result312 -X, --exec-batch <cmd> Execute a command with all search results at once313 -E, --exclude <pattern>... Exclude entries that match the given glob pattern314 -c, --color <when> When to use colors: never, *auto*, always315 -S, --size <size>... Limit results based on the size of files.316 --changed-within <date|dur> Filter by file modification time (newer than)317 --changed-before <date|dur> Filter by file modification time (older than)318319ARGS:Update READMEsharkdpbefore adoption2340bab
line 320why, one step back320 <pattern> the search pattern - a regular expression unless '--glob' is used (optional)Fix warningssharkdpbefore adoption1d16cd8
lines 321–455why, one step back321 <path>... the root directory for the filesystem search (optional)322```323324This is the output of `fd -h`. To see the full set of command-line options, use `fd --help` which325also includes a much more detailed help text.326327## Tutorial328329First, to get an overview of all available command line options, you can either run330`fd -h` for a concise help message (see above) or `fd --help` for a more detailed331version.332333### Simple search334335*fd* is designed to find entries in your filesystem. The most basic search you can perform is to336run *fd* with a single argument: the search pattern. For example, assume that you want to find an337old script of yours (the name included `netflix`):338``` bash339> fd netfl340Software/python/imdb-ratings/netflix-details.py341```342If called with just a single argument like this, *fd* searches the current directory recursively343for any entries that *contain* the pattern `netfl`.344345### Regular expression search346347The search pattern is treated as a regular expression. Here, we search for entries that start348with `x` and end with `rc`:349``` bash350> cd /etc351> fd '^x.*rc$'352X11/xinit/xinitrc353X11/xinit/xserverrc354```355356### Specifying the root directory357358If we want to search a specific directory, it can be given as a second argument to *fd*:359``` bash360> fd passwd /etc361/etc/default/passwd362/etc/pam.d/passwd363/etc/passwd364```365366### Running *fd* without any arguments367368*fd* can be called with no arguments. This is very useful to get a quick overview of all entries369in the current directory, recursively (similar to `ls -R`):370``` bash371> cd fd/tests372> fd373testenv374testenv/mod.rs375tests.rs376```377378If you want to use this functionality to list all files in a given directory, you have to use379a catch-all pattern such as `.` or `^`:380``` bash381> fd . fd/tests/382testenv383testenv/mod.rs384tests.rs385```386387### Searching for a particular file extension388389Often, we are interested in all files of a particular type. This can be done with the `-e` (or390`--extension`) option. Here, we search for all Markdown files in the fd repository:391``` bash392> cd fd393> fd -e md394CONTRIBUTING.md395README.md396```397398The `-e` option can be used in combination with a search pattern:399``` bash400> fd -e rs mod401src/fshelper/mod.rs402src/lscolors/mod.rs403tests/testenv/mod.rs404```405406### Hidden and ignored files407By default, *fd* does not search hidden directories and does not show hidden files in the408search results. To disable this behavior, we can use the `-H` (or `--hidden`) option:409``` bash410> fd pre-commit411> fd -H pre-commit412.git/hooks/pre-commit.sample413```414415If we work in a directory that is a Git repository (or includes Git repositories), *fd* does not416search folders (and does not show files) that match one of the `.gitignore` patterns. To disable417this behavior, we can use the `-I` (or `--no-ignore`) option:418``` bash419> fd num_cpu420> fd -I num_cpu421target/debug/deps/libnum_cpus-f5ce7ef99006aa05.rlib422```423424To really search *all* files and directories, simply combine the hidden and ignore features to show425everything (`-HI`).426427### Excluding specific files or directories428429Sometimes we want to ignore search results from a specific subdirectory. For example, we might430want to search all hidden files and directories (`-H`) but exclude all matches from `.git`431directories. We can use the `-E` (or `--exclude`) option for this. It takes an arbitrary glob432pattern as an argument:433``` bash434> fd -H -E .git …435```436437We can also use this to skip mounted directories:438``` bash439> fd -E /mnt/external-drive …440```441442.. or to skip certain file types:443``` bash444> fd -E '*.bak' …445```446447To make exclude-patterns like these permanent, you can create a `.fdignore` file. They work like448`.gitignore` files, but are specific to `fd`. For example:449``` bash450> cat ~/.fdignore451/mnt/external-drive452*.bak453```454Note: `fd` also supports `.ignore` files that are used by other programs such as `rg` or `ag`.455Add global fdignore supportBobbie Soedirgobefore adoption79d5a5b
lines 456–459why, one step back456If you want `fd` to ignore these patterns globally, you can put them in `fd`'s global ignore file.457This is usually located in `~/.config/fd/ignore` in macOS or Linux, and `%APPDATA%\fd\ignore` in458Windows.459Fix warningssharkdpbefore adoption1d16cd8
lines 460–554why, one step back460### Using fd with `xargs` or `parallel`461462If we want to run a command on all search results, we can pipe the output to `xargs`:463``` bash464> fd -0 -e rs | xargs -0 wc -l465```466Here, the `-0` option tells *fd* to separate search results by the NULL character (instead of467newlines). In the same way, the `-0` option of `xargs` tells it to read the input in this way.468469### Deleting files470471You can use `fd` to remove all files and directories that are matched by your search pattern.472If you only want to remove files, you can use the `--exec-batch`/`-X` option to call `rm`. For473example, to recursively remove all `.DS_Store` files, run:474``` bash475> fd -H '^\.DS_Store$' -tf -X rm476```477If you are unsure, always call `fd` without `-X rm` first. Alternatively, use `rm`s "interactive"478option:479``` bash480> fd -H '^\.DS_Store$' -tf -X rm -i481```482483If you also want to remove a certain class of directories, you can use the same technique. You will484have to use `rm`s `--recursive`/`-r` flag to remove directories.485486Note: there are scenarios where using `fd … -X rm -r` can cause race conditions: if you have a487path like `…/foo/bar/foo/…` and want to remove all directories named `foo`, you can end up in a488situation where the outer `foo` directory is removed first, leading to (harmless) *"'foo/bar/foo':489No such file or directory"* errors in the `rm` call.490491### Troubleshooting492493#### `fd` does not find my file!494495Remember that `fd` ignores hidden directories and files by default. It also ignores patterns496from `.gitignore` files. If you want to make sure to find absolutely every possible file, always497use the options `-H` and `-I` to disable these two features:498``` bash499> fd -HI …500```501502#### `fd` doesn't seem to interpret my regex pattern correctly503504A lot of special regex characters (like `[]`, `^`, `$`, ..) are also special characters in your505shell. If in doubt, always make sure to put single quotes around the regex pattern:506507``` bash508> fd '^[A-Z][0-9]+$'509```510511If your pattern starts with a dash, you have to add `--` to signal the end of command line512options. Otherwise, the pattern will be interpreted as a command-line option. Alternatively,513use a character class with a single hyphen character:514515``` bash516> fd -- '-pattern'517> fd '[-]pattern'518```519520### Integration with other programs521522#### Using fd with `fzf`523524You can use *fd* to generate input for the command-line fuzzy finder [fzf](https://github.com/junegunn/fzf):525``` bash526export FZF_DEFAULT_COMMAND='fd --type file'527export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"528```529530Then, you can type `vim <Ctrl-T>` on your terminal to open fzf and search through the fd-results.531532Alternatively, you might like to follow symbolic links and include hidden files (but exclude `.git` folders):533``` bash534export FZF_DEFAULT_COMMAND='fd --type file --follow --hidden --exclude .git'535```536537You can even use fd's colored output inside fzf by setting:538``` bash539export FZF_DEFAULT_COMMAND="fd --type file --color=always"540export FZF_DEFAULT_OPTS="--ansi"541```542543For more details, see the [Tips section](https://github.com/junegunn/fzf#tips) of the fzf README.544545#### Using fd with `emacs`546547The emacs package [find-file-in-project](https://github.com/technomancy/find-file-in-project) can548use *fd* to find files.549550After installing `find-file-in-project`, add the line `(setq ffip-use-rust-fd t)` to your551`~/.emacs` or `~/.emacs.d/init.el` file.552553In emacs, run `M-x find-file-in-project-by-selected` to find matching files. Alternatively, run554`M-x find-file-in-project` to list all available files in the project.Fix LICENSEShun Sakaibefore adoption5628904
line 555why, one step back555Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046
lines 556–578why, one step back556#### Printing fd's output as a tree557558To format the output of `fd` similar to the `tree` command, install [`as-tree`] and pipe the output559of `fd` to `as-tree`:560```bash561fd | as-tree562```563564This can be more useful than running `tree` by itself because `tree` does not ignore any files by565default, nor does it support as rich a set of options as `fd` does to control what to print:566```bash567❯ fd --extension rs | as-tree568.569├── build.rs570└── src571 ├── app.rs572 └── error.rs573```574575For more information about `as-tree`, see [the `as-tree` README][`as-tree`].576577[`as-tree`]: https://github.com/jez/as-tree578Add tmccombs as maintainerDavid Peterbefore adoption6f2c8cd
lines 579–583why, one step back579## Maintainers580581- [sharkdp](https://github.com/sharkdp)582- [tmccombs](https://github.com/tmccombs)583Fix LICENSEShun Sakaibefore adoption5628904
lines 584–589why, one step back584## License585Copyright (c) 2017-2020 The fd developers586587`fd` is distributed under the terms of both the MIT License and the Apache License 2.0.588589See the [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) files for license details.