README.md
This file
Path
README.md
293 lines · 10.5 KiB · Markdown
Last changed by
README and man page updates.sharkdpbefore adoption7b8d932
History of this fileTake it
Re-write in rustsharkdpbefore adoption12bfee0
line 1why, one step back1# fdREADME updatessharkdpbefore adoption92e2fd3
line 2why, one step back2[](https://travis-ci.org/sharkdp/fd)Add badgessharkdpbefore adoption8073635
line 3why, one step back3[](https://ci.appveyor.com/project/sharkdp/fd)Add crates.io badgeDavid Peterbefore adoptiond8c588d
line 4why, one step back4[](https://crates.io/crates/fd-find)FeaturesDavid Peterbefore adoption490c1ef
line 5why, one step back5Update READMEsharkdpbefore adoption7f49489
lines 6–7why, one step back6*fd* is a simple, fast and user-friendly alternative to7[*find*](https://www.gnu.org/software/findutils/).README updatessharkdpbefore adoption92e2fd3
line 8why, one step back8Update READMEsharkdpbefore adoption7f49489
lines 9–10why, one step back9While it does not seek to mirror all of *find*'s powerful functionality, it provides sensible10(opinionated) defaults for [80%](https://en.wikipedia.org/wiki/Pareto_principle) of the use cases.Update README.mdDavid Peterbefore adoption8e41713
line 11why, one step back11README updatessharkdpbefore adoption92e2fd3
lines 12–13why, one step back12## Features13* Convenient syntax: `fd PATTERN` instead of `find -iname '*PATTERN*'`.Update benchmark resultsDavid Peterbefore adoptiond67b1bb
line 14why, one step back14* Colorized terminal output (similar to *ls*).Link to benchmark sectionDavid Peterbefore adoption0cd9d8c
line 15why, one step back15* It's *fast* (see [benchmarks](#benchmark) below).Update README.mdDavid Peterbefore adoption8e41713
lines 16–18why, one step back16* Smart case: the search is case-insensitive by default. It switches to17 case-sensitive if the pattern contains an uppercase18 character[\*](http://vimdoc.sourceforge.net/htmldoc/options.html#'smartcase').Update README.mdDavid Peterbefore adoption7b1a457
lines 19–22why, one step back19* Ignores hidden directories and files, by default.20* Ignores patterns from your `.gitignore`, by default.21* Regular expressions.22* Unicode-awareness.Update READMEsharkdpbefore adoption7f49489
lines 23–24why, one step back23* The command name is *50%* shorter[\*](https://github.com/ggreer/the_silver_searcher) than24 `find` :-).Merge pull request #116 from mmstick/execDavid Peterbefore adoptione0eab07
line 25why, one step back25* Parallel command execution with a syntax similar to GNU Parallel.Build instructionsDavid Peterbefore adoption8acb30b
line 26why, one step back26Update README.mdDavid Peterbefore adoption6a705b5
line 27why, one step back27## DemoUpdate README.mdDavid Peterbefore adoptionb97038f
line 28why, one step back28Update demo videoDavid Peterbefore adoption3afd216
line 29why, one step back29ExamplesDavid Peterbefore adoptiondddd47e
line 30why, one step back30Added benchmark resultsDavid Peterbefore adoption7b00772
line 31why, one step back31## BenchmarkUpdate benchmark resultsDavid Peterbefore adoptiond67b1bb
lines 32–37why, one step back32Let's search my home folder for files that end in `[0-9].jpg`. It contains ~150.00033subdirectories and about a million files. For averaging and statistical analysis, I'm using34[bench](https://github.com/Gabriel439/bench). All benchmarks are performed for a "warm35cache". Results for a cold cache are similar.3637Let's start with `find`:Update benchmark results, see #31sharkdpbefore adoptionc74c2ca
line 38why, one step back38```Update benchmark resultsDavid Peterbefore adoptiond67b1bb
lines 39–41why, one step back39find ~ -iregex '.*[0-9]\.jpg$'4041time 6.265 s (6.127 s .. NaN s)Update benchmark results, see #31sharkdpbefore adoptionc74c2ca
line 42why, one step back42 1.000 R² (1.000 R² .. 1.000 R²)Update benchmark resultsDavid Peterbefore adoptiond67b1bb
lines 43–45why, one step back43mean 6.162 s (6.140 s .. 6.181 s)44std dev 31.73 ms (0.0 s .. 33.48 ms)45```Added benchmark resultsDavid Peterbefore adoption7b00772
line 46why, one step back46Update benchmark resultsDavid Peterbefore adoptiond67b1bb
lines 47–51why, one step back47`find` is much faster if it does not need to perform a regular-expression search:48```49find ~ -iname '*[0-9].jpg'5051time 2.866 s (2.754 s .. 2.964 s)Update benchmark results, see #31sharkdpbefore adoptionc74c2ca
line 52why, one step back52 1.000 R² (0.999 R² .. 1.000 R²)Update benchmark resultsDavid Peterbefore adoptiond67b1bb
lines 53–54why, one step back53mean 2.860 s (2.834 s .. 2.875 s)54std dev 23.11 ms (0.0 s .. 25.09 ms)Added benchmark resultsDavid Peterbefore adoption7b00772
line 55why, one step back55```Update benchmark results, see #31sharkdpbefore adoptionc74c2ca
line 56why, one step back56Update benchmark resultsDavid Peterbefore adoptiond67b1bb
lines 57–61why, one step back57Now let's try the same for `fd`. Note that `fd` *always* performs a regular expression58search. The options `--hidden` and `--no-ignore` are needed for a fair comparison,59otherwise `fd` does not have to traverse hidden folders and ignored paths (see below):60```61fd --hidden --no-ignore '.*[0-9]\.jpg$' ~Added benchmark resultsDavid Peterbefore adoption7b00772
line 62why, one step back62Update benchmark resultsDavid Peterbefore adoptiond67b1bb
lines 63–88why, one step back63time 892.6 ms (839.0 ms .. 915.4 ms)64 0.999 R² (0.997 R² .. 1.000 R²)65mean 871.2 ms (857.9 ms .. 881.3 ms)66std dev 15.50 ms (0.0 s .. 17.49 ms)67```68For this particular example, `fd` is approximately seven times faster than `find -iregex`69and about three times faster than `find -iname`. By the way, both tools found the exact70same 14030 files :smile:.7172Finally, let's run `fd` without `--hidden` and `--no-ignore` (this can lead to different73search results, of course):74```75fd '[0-9]\.jpg$' ~7677time 159.5 ms (155.8 ms .. 165.3 ms)78 0.999 R² (0.996 R² .. 1.000 R²)79mean 158.7 ms (156.5 ms .. 161.6 ms)80std dev 3.263 ms (2.401 ms .. 4.298 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 might85be different for you! I encourage everyone to try it out on their own.8687Concerning *fd*'s speed, the main credit goes to the `regex` and `ignore` crates that are also used88in [ripgrep](https://github.com/BurntSushi/ripgrep) (check it out!).Link to benchmark sectionDavid Peterbefore adoption0cd9d8c
lines 89–98why, one step back8990## Colorized output91`fd` can colorize files by extension, just like `ls`. In order for this to work, the environment92variable [`LS_COLORS`](https://linux.die.net/man/5/dir_colors) has to be set. Typically, the value93of this variable is set by the `dircolors` command which provides a convenient configuration format94to define colors for different file formats.95On most distributions, `LS_COLORS` should be set already. If you are looking for alternative, more96complete (and more colorful) variants, see97[here](https://github.com/seebi/dircolors-solarized) or98[here](https://github.com/trapd00r/LS_COLORS).Merge pull request #116 from mmstick/execDavid Peterbefore adoptione0eab07
line 99why, one step back99Updates for the parallel command execution partsharkdpbefore adoption7ecb623
lines 100–103why, one step back100## Parallel command execution101If the `-x`/`--exec` option is specified alongside a command template, a job pool will be created102for executing commands in parallel for each discovered path as the input. The syntax for generating103commands is similar to that of GNU Parallel:Merge pull request #116 from mmstick/execDavid Peterbefore adoptione0eab07
line 104why, one step back104Updates for the parallel command execution partsharkdpbefore adoption7ecb623
lines 105–110why, one step back105- `{}`: A placeholder token that will be replaced with the path of the search result106 (`documents/images/party.jpg`).107- `{.}`: Like `{}`, but without the file extension (`documents/images/party`).108- `{/}`: A placeholder that will be replaced by the basename of the search result (`party.jpg`).109- `{//}`: Uses the parent of the discovered path (`documents/images`).110- `{/.}`: Uses the basename, with the extension removed (`party`).Merge pull request #116 from mmstick/execDavid Peterbefore adoptione0eab07
line 111why, one step back111Updates for the parallel command execution partsharkdpbefore adoption7ecb623
lines 112–113why, one step back112``` bash113# Convert all jpg files to png filesFix --exec examples in READMEsharkdpbefore adoption19afb15
line 114why, one step back114fd -e jpg -x 'convert {} {.}.png'Merge pull request #116 from mmstick/execDavid Peterbefore adoptione0eab07
line 115why, one step back115Updates for the parallel command execution partsharkdpbefore adoption7ecb623
lines 116–117why, one step back116# Unpack all zip files (if no placeholder is given, the path is appended):117fd -e zip -x unzipMerge pull request #116 from mmstick/execDavid Peterbefore adoptione0eab07
line 118why, one step back118Updates for the parallel command execution partsharkdpbefore adoption7ecb623
line 119why, one step back119# Convert all flac files into opus files:Fix --exec examples in READMEsharkdpbefore adoption19afb15
line 120why, one step back120fd -e flac -x 'ffmpeg -i {} -c:a libopus {.}.opus'Merge pull request #116 from mmstick/execDavid Peterbefore adoptione0eab07
line 121why, one step back121```Add note about regex and ignore cratesDavid Peterbefore adoptionb347160
line 122why, one step back122Update install instructionsDavid Peterbefore adoptiona4e48cf
line 123why, one step back123## InstallAdd new cargo install instructionssharkdpbefore adoptionf1f537b
line 124why, one step back124With Rust's package manager [cargo](https://github.com/rust-lang/cargo), you can install *fd* via:Update install instructionsDavid Peterbefore adoptiona4e48cf
line 125why, one step back125```Add new cargo install instructionssharkdpbefore adoptionf1f537b
line 126why, one step back126cargo install fd-findUpdate install instructionsDavid Peterbefore adoptiona4e48cf
line 127why, one step back127```README and man page updates.sharkdpbefore adoption7b8d932
line 128why, one step back128Note that rust version *1.19.0* or later is required.Update install instructionsDavid Peterbefore adoptiona4e48cf
line 129why, one step back129The release page of this repository also includes precompiled binaries for Linux.Update install instructionsDavid Peterbefore adoptioneb72875
line 130why, one step back130Add link to Homebrew formulaDavid Peterbefore adoption6c69b98
line 131why, one step back131On **macOS**, you can use [Homebrew](http://braumeister.org/formula/fd):Update install instructionsDavid Peterbefore adoptioneb72875
lines 132–134why, one step back132```133brew install fd134```Added benchmark resultsDavid Peterbefore adoption7b00772
line 135why, one step back135README: Arch Linux has package fd-rs in official reposBen Morganbefore adoption200dfaa
line 136why, one step back136On **Arch Linux**, you can install the package from the official repos:Merge pull request #51 from wezm/patch-1David Peterbefore adoptionfb5ba2c
line 137why, one step back137```README: Arch Linux has package fd-rs in official reposBen Morganbefore adoption200dfaa
line 138why, one step back138pacman -S fd-rsMerge pull request #51 from wezm/patch-1David Peterbefore adoptionfb5ba2c
lines 139–140why, one step back139```140Added another way of installationMattbefore adoption08aa06a
lines 141–145why, one step back141On **NixOS**, or any Linux distro you can use [Nix](https://nixos.org/nix/):142```143nix-env -i fd144```145Update README.mdOli Lalondebefore adoption68a85c7
line 146why, one step back146On **Windows**, you can download the pre-built binaries from the [Release page](https://github.com/sharkdp/fd/releases).Add Windows install instructionsDavid Peterbefore adoption43b124c
line 147why, one step back147Update install instructionsDavid Peterbefore adoptiona4e48cf
line 148why, one step back148## DevelopmentBuild instructionsDavid Peterbefore adoption8acb30b
line 149why, one step back149```bashUpdate development instructionssharkdpbefore adoption4884c23
lines 150–155why, one step back150git clone https://github.com/sharkdp/fd151152# Build153cd fd154cargo build155Update development instructionsDavid Peterbefore adoptionb98e4c9
line 156why, one step back156# Run unit tests and integration testsUpdate development instructionssharkdpbefore adoption4884c23
lines 157–160why, one step back157cargo test158159# Install160cargo installBuild instructionsDavid Peterbefore adoption8acb30b
line 161why, one step back161```Add command-line optionssharkdpbefore adoptiona234984
lines 162–170why, one step back162163## Command-line options164```165USAGE:166 fd [FLAGS/OPTIONS] [<pattern>] [<path>]167168FLAGS:169 -H, --hidden Search hidden files and directories170 -I, --no-ignore Do not respect .(git)ignore filesUpdate USAGE.David Peterbefore adoption083b1cf
line 171why, one step back171 -s, --case-sensitive Case-sensitive search (default: smart case)Updates and preparations for v5.0sharkdpbefore adoptione9cf8af
line 172why, one step back172 -i, --ignore-case Case-insensitive search (default: smart case)Add command-line optionssharkdpbefore adoptiona234984
line 173why, one step back173 -a, --absolute-path Show absolute instead of relative pathsUpdate USAGE.David Peterbefore adoption083b1cf
lines 174–176why, one step back174 -L, --follow Follow symbolic links175 -p, --full-path Search full path (default: file-/dirname only)176 -0, --print0 Separate results by the null characterAdd command-line optionssharkdpbefore adoptiona234984
lines 177–180why, one step back177 -h, --help Prints help information178 -V, --version Prints version information179180OPTIONS:README and man page updates.sharkdpbefore adoption7b8d932
lines 181–188why, one step back181 -d, --max-depth <depth> Set maximum search depth (default: none)182 -t, --type <filetype> Filter by type: f(ile), d(irectory), (sym)l(ink)183 -e, --extension <ext> Filter by file extension184 -x, --exec <cmd> Execute the given command for each search result185 -E, --exclude <pattern>... Exclude entries that match the given glob pattern.186 -c, --color <when> When to use colors: never, *auto*, always187 -j, --threads <num> Set number of threads to use for searching &188 executingAdd command-line optionssharkdpbefore adoptiona234984
lines 189–193why, one step back189190ARGS:191 <pattern> the search pattern, a regular expression (optional)192 <path> the root directory for the filesystem search (optional)193```Add examples to README (#68)Rickybefore adoption3b55edf
line 194why, one step back194First update for tutorialsharkdpbefore adoption080e8a9
line 195why, one step back195## TutorialAdd examples to README (#68)Rickybefore adoption3b55edf
line 196why, one step back196Updates for the tutorialsharkdpbefore adoption5863a5e
lines 197–199why, one step back197First, to get an overview of all available command line options, you can either run198`fd -h` for a concise help message (see above) or `fd --help` for a more detailed199version.Add examples to README (#68)Rickybefore adoption3b55edf
line 200why, one step back200Updates for the tutorialsharkdpbefore adoption5863a5e
line 201why, one step back201### Simple searchAdd examples to README (#68)Rickybefore adoption3b55edf
line 202why, one step back202Updates for the tutorialsharkdpbefore adoption5863a5e
lines 203–208why, one step back203*fd* is designed to find entries in your filesystem. The most basic search you can perform is to204run *fd* with a single argument: the search pattern. For example, assume that you want to find an205old script of yours (the name included `netflix`):206``` bash207> fd netfl208Software/python/imdb-ratings/netflix-details.pyUpdated tutorial with real-world examplessharkdpbefore adoptiond32fe02
line 209why, one step back209```Updates for the tutorialsharkdpbefore adoption5863a5e
lines 210–211why, one step back210If called with just a single argument like this, *fd* searches the current directory recursively211for any entries that *contain* the pattern `netfl`.Updated tutorial with real-world examplessharkdpbefore adoptiond32fe02
line 212why, one step back212Updates for the tutorialsharkdpbefore adoption5863a5e
line 213why, one step back213### Regular expression searchUpdated tutorial with real-world examplessharkdpbefore adoptiond32fe02
line 214why, one step back214Updates for the tutorialsharkdpbefore adoption5863a5e
lines 215–221why, one step back215The search pattern is treated as a regular expression. Here, we search for entries that start216with `x` and end with `rc`:217``` bash218> cd /etc219> fd '^x.*rc$'220X11/xinit/xinitrc221X11/xinit/xserverrcAdd examples to README (#68)Rickybefore adoption3b55edf
lines 222–223why, one step back222```223Updates for the tutorialsharkdpbefore adoption5863a5e
line 224why, one step back224### Specifying the root directoryAdd examples to README (#68)Rickybefore adoption3b55edf
line 225why, one step back225Updates for the tutorialsharkdpbefore adoption5863a5e
lines 226–231why, one step back226If we want so search a specific directory, it can be given as a second argument to *fd*:227``` bash228> fd passwd /etc229/etc/default/passwd230/etc/pam.d/passwd231/etc/passwdAdd examples to README (#68)Rickybefore adoption3b55edf
lines 232–233why, one step back232```233Updates for the tutorialsharkdpbefore adoption5863a5e
lines 234–243why, one step back234### Running *fd* without any arguments235236*fd* can be called with no arguments. This is very useful to get a quick overview of all entries237in the current directory, recursively (similar to `ls -R`):238``` bash239> cd fd/tests240> fd241testenv242testenv/mod.rs243tests.rsAdd examples to README (#68)Rickybefore adoption3b55edf
lines 244–245why, one step back244```245Updates for the tutorialsharkdpbefore adoption5863a5e
lines 246–254why, one step back246### Searching for a particular file extension247248Often, we are interested in all files of a particular type. This can be done with the `-e` (or249`--extension`) option. Here, we search for all Markdown files in the fd repository:250``` bash251> cd fd252> fd -e md253CONTRIBUTING.md254README.mdAdd examples to README (#68)Rickybefore adoption3b55edf
lines 255–256why, one step back255```256Updates for the tutorialsharkdpbefore adoption5863a5e
lines 257–262why, one step back257The `-e` option can be used in combination with a search pattern:258``` bash259> fd -e rs mod260src/fshelper/mod.rs261src/lscolors/mod.rs262tests/testenv/mod.rsAdd examples to README (#68)Rickybefore adoption3b55edf
lines 263–264why, one step back263```264Updates for the tutorialsharkdpbefore adoption5863a5e
lines 265–271why, one step back265### Hidden and ignored files266By default, *fd* does not search hidden directories and does not show hidden files in the267search results. To disable this behavior, we can use the `-H` (or `--hidden`) option:268``` bash269> fd pre-commit270> fd -H pre-commit271.git/hooks/pre-commit.sampleAdd examples to README (#68)Rickybefore adoption3b55edf
lines 272–273why, one step back272```273Updates for the tutorialsharkdpbefore adoption5863a5e
lines 274–280why, one step back274If we work in a directory that is a Git repository (or includes Git repositories), *fd* does not275search folders (and does not show files) that match one of the `.gitignore` patterns. To disable276this behavior, we can use the `-I` (or `--ignore`) option:277``` bash278> fd num_cpu279> fd -I num_cpu280target/debug/deps/libnum_cpus-f5ce7ef99006aa05.rlibAdd examples to README (#68)Rickybefore adoption3b55edf
lines 281–282why, one step back281```282Updates for the tutorialsharkdpbefore adoption5863a5e
lines 283–284why, one step back283To really search *all* files and directories, simply combine the hidden and ignore features to show284everything (`-HI`).Updated tutorial with real-world examplessharkdpbefore adoptiond32fe02
line 285why, one step back285Updates for the tutorialsharkdpbefore adoption5863a5e
line 286why, one step back286### Using fd with `xargs` or `parallel`Updated tutorial with real-world examplessharkdpbefore adoptiond32fe02
line 287why, one step back287Updates for the tutorialsharkdpbefore adoption5863a5e
lines 288–290why, one step back288If we want to run a command on all search results, we can pipe the output to `xargs`:289``` bash290> fd -0 -e rs | xargs -0 wc -lAdd examples to README (#68)Rickybefore adoption3b55edf
line 291why, one step back291```Updates for the tutorialsharkdpbefore adoption5863a5e
lines 292–293why, one step back292Here, the `-0` option tells *fd* to separate search results by the NULL character (instead of .293newlines) In the same way, the `-0` option of `xargs` tells it to read the input in this way .