Skip to content
Myr

README.md

This file

Path

README.md

555 lines · 18.3 KiB · Markdown

Last changed by

Update USAGE sectionsharkdpbefore adoptiona06efe1

History of this file

Take it

The walk stopped after 200 commits: lines older than f064ee5 point at it.

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 1–2why, one step back
1# fd
2[![Build Status](https://travis-ci.org/sharkdp/fd.svg?branch=master)](https://travis-ci.org/sharkdp/fd)

Show `master` build stateDavid Peterbefore adoption8196f79

line 3why, one step back
3[![Build status](https://ci.appveyor.com/api/projects/status/21c4p5fwggc5gy3j/branch/master?svg=true)](https://ci.appveyor.com/project/sharkdp/fd/branch/master)

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 4–5why, one step back
4[![Version info](https://img.shields.io/crates/v/fd-find.svg)](https://crates.io/crates/fd-find)
5[中文](https://github.com/chinanf-boy/fd-zh)

Add link for Koreanspearkkkbefore adoption12bd321

line 6why, one step back
6[한국어](https://github.com/spearkkk/fd-kor)

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 7–44why, one step back
7
8*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## Demo3031![Demo](doc/screencast.svg)3233## 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 s

Add instructions for npmPablo Varelabefore adoption801816e

line 45why, one step back
45

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 46–53why, one step back
46 Range (min … max): 7.133 s … 7.385 s
47```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 s

Add instructions for npmPablo Varelabefore adoption801816e

line 54why, one step back
54

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 55–64why, one step back
55 Range (min … max): 3.876 s … 3.964 s
56```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 ms

Add instructions for npmPablo Varelabefore adoption801816e

line 65why, one step back
65

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 66–78why, one step back
66 Range (min … max): 786.0 ms … 870.7 ms
67```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 ms

Add instructions for npmPablo Varelabefore adoption801816e

line 79why, one step back
79

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 80–84why, one step back
80 Range (min … max): 118.8 ms … 140.0 ms
81```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 might

Add instructions for npmPablo Varelabefore adoption801816e

line 85why, one step back
85be different for you! I encourage everyone to try it out on their own. See

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 86–100why, one step back
86[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.96On most distributions, `LS_COLORS` should be set already. If you are looking for alternative, more97complete (and more colorful) variants, see98[here](https://github.com/seebi/dircolors-solarized) or99[here](https://github.com/trapd00r/LS_COLORS).100

Update README.mdDavid Peterbefore adoption9c9bb12

line 101why, one step back
101`fd` also honors the [`NO_COLOR`](https://no-color.org/) environment variable.

honor the NO_COLOR env varDave Parfittbefore adoption70448b0

line 102why, one step back
102

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 103–128why, one step back
103## Parallel command execution
104If 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```128

Clarify statement about number of threads for parallell executionDavid Peterbefore adoption630749f

line 129why, one step back
129The number of threads used for command execution can be set with the `--threads`/`-j` option.

Added detail on parallel execution job pool to man page and README.Jason Heerisbefore adoption1daa454

line 130why, one step back
130

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 131–135why, one step back
131## Installation
132133### On Ubuntu134*... and other Debian-based Linux distributions.*135

Update Ubuntu install instructionsDavid Peterbefore adoptionac2dae0

lines 136–146why, one step back
136If you run Ubuntu 19.04 (Disco Dingo) or newer, you can install the
137[officially maintained package](https://packages.ubuntu.com/disco/fd-find):138```139sudo apt install fd-find140```141Note that the binary is called `fdfind` as the binary name `fd` is already used by another package.142It is recommended that you add an `alias fd=fdfind` to your shells initialization file, in order to143use `fd` in the same way as in this documentation.144145If you use an older version of Ubuntu, you can download the latest `.deb` package from the146[release page](https://github.com/sharkdp/fd/releases) and install it via:

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

line 147why, one step back
147``` bash

Bump version to 8.0sharkdpbefore adoptionee1a9f5

line 148why, one step back
148sudo dpkg -i fd_8.0.0_amd64.deb # adapt version number and architecture

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

line 149why, one step back
149```

Update info about debian & ubuntuSylvestre Ledrubefore adoptionec99e5d

line 150why, one step back
150

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 151–152why, one step back
151### On Debian
152

Adapt READMEsharkdpbefore adoption04debe5

lines 153–154why, one step back
153If you run Debian Buster or newer, you can install the
154[officially maintained Debian package](https://tracker.debian.org/pkg/rust-fd-find):

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 155–157why, one step back
155```
156sudo apt-get install fd-find157```

Adapt READMEsharkdpbefore adoption04debe5

lines 158–160why, one step back
158Note that the binary is called `fdfind` as the binary name `fd` is already used by another package.
159It is recommended that you add an `alias fd=fdfind` to your shells initialization file, in order to160use `fd` in the same way as in this documentation.

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 161–174why, one step back
161
162### On Fedora163164Starting with Fedora 28, you can install `fd` from the official package sources:165``` bash166dnf install fd-find167```168169For older versions, you can use this [Fedora copr](https://copr.fedorainfracloud.org/coprs/keefle/fd/) to install `fd`:170``` bash171dnf copr enable keefle/fd172dnf install fd173```174

Add Alpine Linux installation instructionsChloe Kudryavtsevbefore adoption0b04bd1

lines 175–182why, one step back
175### On Alpine Linux
176177You can install [the fd package](https://pkgs.alpinelinux.org/packages?name=fd)178from the official sources, provided you have the appropriate repository enabled:179```180apk add fd181```182

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 183–211why, one step back
183### On Arch Linux
184185You can install [the fd package](https://www.archlinux.org/packages/community/x86_64/fd/) from the official repos:186```187pacman -S fd188```189### On Gentoo Linux190191You can use [the fd ebuild](https://packages.gentoo.org/packages/sys-apps/fd) from the official repo:192```193emerge -av fd194```195196### On openSUSE Linux197198You can install [the fd package](https://software.opensuse.org/package/fd) from the official repo:199```200zypper in fd201```202203### On Void Linux204205You can install `fd` via xbps-install:206```207xbps-install -S fd208```209210### On macOS211

Fix homebrew formula linkAdam Smithbefore adoption3c6fab3

line 212why, one step back
212You can install `fd` with [Homebrew](https://formulae.brew.sh/formula/fd):

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 213–244why, one step back
213```
214brew install fd215```216217… or with MacPorts:218```219sudo port install fd220```221222### On Windows223224You can download pre-built binaries from the [release page](https://github.com/sharkdp/fd/releases).225226Alternatively, you can install `fd` via [Scoop](http://scoop.sh):227```228scoop install fd229```230231Or via [Chocolatey](https://chocolatey.org):232```233choco install fd234```235236### On NixOS / via Nix237238You can use the [Nix package manager](https://nixos.org/nix/) to install `fd`:239```240nix-env -i fd241```242243### On FreeBSD244

Update FreeBSD install instructionsTobias Kortkampbefore adoptionf3ec3d9

line 245why, one step back
245You can install [the fd-find package](https://www.freshports.org/sysutils/fd) from the official repo:

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

line 246why, one step back
246```

Update FreeBSD install instructionsTobias Kortkampbefore adoptionf3ec3d9

line 247why, one step back
247pkg install fd-find

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 248–249why, one step back
248```
249

Add instructions for npmPablo Varelabefore adoption801816e

lines 250–255why, one step back
250### From NPM
251252On linux and macOS, you can install the [fd-find](https://npm.im/fd-find) package:253254```255npm install -g fd-find

Add OpenBSD installation stepsevitalisbefore adoptionf15540e

lines 256–257why, one step back
256```
257

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 258–263why, one step back
258### From source
259260With Rust's package manager [cargo](https://github.com/rust-lang/cargo), you can install *fd* via:261```262cargo install fd-find263```

Bump min. required Rust version to 1.36sharkdpbefore adoptiondd07bc9

line 264why, one step back
264Note that rust version *1.36.0* or later is required.

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 265–290why, one step back
265
266### From binaries267268The [release page](https://github.com/sharkdp/fd/releases) includes precompiled binaries for Linux, macOS and Windows.269270## Development271```bash272git clone https://github.com/sharkdp/fd273274# Build275cd fd276cargo build277278# Run unit tests and integration tests279cargo test280281# Install282cargo install283```284285## Command-line options286```287USAGE:288 fd [FLAGS/OPTIONS] [<pattern>] [<path>...]289290FLAGS:

Update READMEsharkdpbefore adoption2340bab

lines 291–296why, one step back
291 -H, --hidden Search hidden files and directories
292 -I, --no-ignore Do not respect .(git|fd)ignore files293 -s, --case-sensitive Case-sensitive search (default: smart case)294 -i, --ignore-case Case-insensitive search (default: smart case)295 -g, --glob Glob-based search (default: regular expression)296 -a, --absolute-path Show absolute instead of relative paths

Update USAGE sectionsharkdpbefore adoptiona06efe1

line 297why, one step back
297 -l, --list-details Use a long listing format with file metadata

Update READMEsharkdpbefore adoption2340bab

lines 298–302why, one step back
298 -L, --follow Follow symbolic links
299 -p, --full-path Search full path (default: file-/dirname only)300 -0, --print0 Separate results by the null character301 -h, --help Prints help information302 -V, --version Prints version information

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 303–306why, one step back
303
304OPTIONS:305 -d, --max-depth <depth> Set maximum search depth (default: none)306 -t, --type <filetype>... Filter by type: file (f), directory (d), symlink (l),

Update USAGE sectionsharkdpbefore adoptiona06efe1

line 307why, one step back
307 executable (x), empty (e), socket (s), pipe (p)

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 308–309why, one step back
308 -e, --extension <ext>... Filter by file extension
309 -x, --exec <cmd> Execute a command for each search result

Update USAGE in READMEsharkdpbefore adoptionf1ab443

line 310why, one step back
310 -X, --exec-batch <cmd> Execute a command with all search results at once

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 311–317why, one step back
311 -E, --exclude <pattern>... Exclude entries that match the given glob pattern
312 -c, --color <when> When to use colors: never, *auto*, always313 -S, --size <size>... Limit results based on the size of files.314 --changed-within <date|dur> Filter by file modification time (newer than)315 --changed-before <date|dur> Filter by file modification time (older than)316317ARGS:

Update READMEsharkdpbefore adoption2340bab

line 318why, one step back
318 <pattern> the search pattern - a regular expression unless '--glob' is used (optional)

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 319–320why, one step back
319 <path>... the root directory for the filesystem search (optional)
320```

Update USAGE in READMEsharkdpbefore adoptionf1ab443

lines 321–323why, one step back
321
322This is the output of `fd -h`. To see the full set of command-line options, use `fd --help` which323also includes a much more detailed help text.

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 324–375why, one step back
324
325## Tutorial326327First, to get an overview of all available command line options, you can either run328`fd -h` for a concise help message (see above) or `fd --help` for a more detailed329version.330331### Simple search332333*fd* is designed to find entries in your filesystem. The most basic search you can perform is to334run *fd* with a single argument: the search pattern. For example, assume that you want to find an335old script of yours (the name included `netflix`):336``` bash337> fd netfl338Software/python/imdb-ratings/netflix-details.py339```340If called with just a single argument like this, *fd* searches the current directory recursively341for any entries that *contain* the pattern `netfl`.342343### Regular expression search344345The search pattern is treated as a regular expression. Here, we search for entries that start346with `x` and end with `rc`:347``` bash348> cd /etc349> fd '^x.*rc$'350X11/xinit/xinitrc351X11/xinit/xserverrc352```353354### Specifying the root directory355356If we want to search a specific directory, it can be given as a second argument to *fd*:357``` bash358> fd passwd /etc359/etc/default/passwd360/etc/pam.d/passwd361/etc/passwd362```363364### Running *fd* without any arguments365366*fd* can be called with no arguments. This is very useful to get a quick overview of all entries367in the current directory, recursively (similar to `ls -R`):368``` bash369> cd fd/tests370> fd371testenv372testenv/mod.rs373tests.rs374```375

Add section about catch-all patterns, closes #385sharkdpbefore adoption2672d84

lines 376–384why, one step back
376If you want to use this functionality to list all files in a given directory, you have to use
377a catch-all pattern such as `.` or `^`:378``` bash379> fd . fd/tests/380testenv381testenv/mod.rs382tests.rs383```384

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 385–462why, one step back
385### Searching for a particular file extension
386387Often, we are interested in all files of a particular type. This can be done with the `-e` (or388`--extension`) option. Here, we search for all Markdown files in the fd repository:389``` bash390> cd fd391> fd -e md392CONTRIBUTING.md393README.md394```395396The `-e` option can be used in combination with a search pattern:397``` bash398> fd -e rs mod399src/fshelper/mod.rs400src/lscolors/mod.rs401tests/testenv/mod.rs402```403404### Hidden and ignored files405By default, *fd* does not search hidden directories and does not show hidden files in the406search results. To disable this behavior, we can use the `-H` (or `--hidden`) option:407``` bash408> fd pre-commit409> fd -H pre-commit410.git/hooks/pre-commit.sample411```412413If we work in a directory that is a Git repository (or includes Git repositories), *fd* does not414search folders (and does not show files) that match one of the `.gitignore` patterns. To disable415this behavior, we can use the `-I` (or `--no-ignore`) option:416``` bash417> fd num_cpu418> fd -I num_cpu419target/debug/deps/libnum_cpus-f5ce7ef99006aa05.rlib420```421422To really search *all* files and directories, simply combine the hidden and ignore features to show423everything (`-HI`).424425### Excluding specific files or directories426427Sometimes we want to ignore search results from a specific subdirectory. For example, we might428want to search all hidden files and directories (`-H`) but exclude all matches from `.git`429directories. We can use the `-E` (or `--exclude`) option for this. It takes an arbitrary glob430pattern as an argument:431``` bash432> fd -H -E .git …433```434435We can also use this to skip mounted directories:436``` bash437> fd -E /mnt/external-drive …438```439440.. or to skip certain file types:441``` bash442> fd -E '*.bak' …443```444445To make exclude-patterns like these permanent, you can create a `.fdignore` file. They work like446`.gitignore` files, but are specific to `fd`. For example:447``` bash448> cat ~/.fdignore449/mnt/external-drive450*.bak451```452Note: `fd` also supports `.ignore` files that are used by other programs such as `rg` or `ag`.453454### Using fd with `xargs` or `parallel`455456If we want to run a command on all search results, we can pipe the output to `xargs`:457``` bash458> fd -0 -e rs | xargs -0 wc -l459```460Here, the `-0` option tells *fd* to separate search results by the NULL character (instead of461newlines). In the same way, the `-0` option of `xargs` tells it to read the input in this way.462

Add a section about "removing files"sharkdpbefore adoption53afcd8

lines 463–484why, one step back
463### Deleting files
464465You can use `fd` to remove all files and directories that are matched by your search pattern.466If you only want to remove files, you can use the `--exec-batch`/`-X` option to call `rm`. For467example, to recursively remove all `.DS_Store` files, run:468``` bash469> fd -H '^\.DS_Store$' -tf -X rm470```471If you are unsure, always call `fd` without `-X rm` first. Alternatively, use `rm`s "interactive"472option:473``` bash474> fd -H '^\.DS_Store$' -tf -X rm -i475```476477If you also want to remove a certain class of directories, you can use the same technique. You will478have to use `rm`s `--recursive`/`-r` flag to remove directories.479480Note: there are scenarios where using `fd … -X rm -r` can cause race conditions: if you have a481path like `…/foo/bar/foo/…` and want to remove all directories named `foo`, you can end up in a482situation where the outer `foo` directory is removed first, leading to (harmless) *"'foo/bar/foo':483No such file or directory"* errors in the `rm` call.484

Add troubleshooting section, closes #386sharkdpbefore adoption85f9db0

lines 485–513why, one step back
485### Troubleshooting
486487#### `fd` does not find my file!488489Remember that `fd` ignores hidden directories and files by default. It also ignores patterns490from `.gitignore` files. If you want to make sure to find absolutely every possible file, always491use the options `-H` and `-I` to disable these two features:492``` bash493> fd -HI …494```495496#### `fd` doesn't seem to interpret my regex pattern correctly497498A lot of special regex characters (like `[]`, `^`, `$`, ..) are also special characters in your499shell. If in doubt, always make sure to put single quotes around the regex pattern:500501``` bash502> fd '^[A-Z][0-9]+$'503```504505If your pattern starts with a dash, you have to add `--` to signal the end of command line506options. Otherwise, the pattern will be interpreted as a command-line option. Alternatively,507use a character class with a single hyphen character:508509``` bash510> fd -- '-pattern'511> fd '[-]pattern'512```513

Properly use .ignore files, see #156sharkdpbefore adoptionf064ee5

lines 514–548why, one step back
514### Integration with other programs
515516#### Using fd with `fzf`517518You can use *fd* to generate input for the command-line fuzzy finder [fzf](https://github.com/junegunn/fzf):519``` bash520export FZF_DEFAULT_COMMAND='fd --type file'521export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"522```523524Then, you can type `vim <Ctrl-T>` on your terminal to open fzf and search through the fd-results.525526Alternatively, you might like to follow symbolic links and include hidden files (but exclude `.git` folders):527``` bash528export FZF_DEFAULT_COMMAND='fd --type file --follow --hidden --exclude .git'529```530531You can even use fd's colored output inside fzf by setting:532``` bash533export FZF_DEFAULT_COMMAND="fd --type file --color=always"534export FZF_DEFAULT_OPTS="--ansi"535```536537For more details, see the [Tips section](https://github.com/junegunn/fzf#tips) of the fzf README.538539#### Using fd with `emacs`540541The emacs package [find-file-in-project](https://github.com/technomancy/find-file-in-project) can542use *fd* to find files.543544After installing `find-file-in-project`, add the line `(setq ffip-use-rust-fd t)` to your545`~/.emacs` or `~/.emacs.d/init.el` file.546547In emacs, run `M-x find-file-in-project-by-selected` to find matching files. Alternatively, run548`M-x find-file-in-project` to list all available files in the project.

Fix LICENSEShun Sakaibefore adoption5628904

lines 549–555why, one step back
549
550## License551Copyright (c) 2017-2020 The fd developers552553`fd` is distributed under the terms of both the MIT License and the Apache License 2.0.554555See the [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) files for license details.