Repository: sharkdp/fd
Stars: 42582
README.md
fd


[δΈζ]
[νκ΅μ΄]
fd is a program to find entries in your filesystem.
It is a simple, fast and user-friendly alternative to find.
While it does not aim to support all of find's powerful functionality, it provides sensible
(opinionated) defaults for a majority of use cases.
Installation β’ How to use β’ Troubleshooting
Features
Intuitive syntax: fd PATTERN instead of find -iname 'PATTERN*'.
* Regular expression (default) and glob-based patterns.
* Very fast due to parallelized directory traversal.
* Uses colors to highlight different file types (same as ls).
* Supports parallel command execution
* Smart case: the search is case-insensitive by default. It switches to
case-sensitive if the pattern contains an uppercase
character\*.
* Ignores hidden directories and files, by default.
* Ignores patterns from your .gitignore, by default.
The command name is 50% shorter\ than
find :-).
Demo
!Demo
How to use
First, to get an overview of all available command line options, you can either runfd -h for a concise help message or fd --help for a more detailed
version.
Simple search
fd is designed to find entries in your filesystem. The most basic search you can perform is to The search pattern is treated as a regular expression. Here, we search for entries that start If we want to search a specific directory, it can be given as a second argument to fd: fd can be called with no arguments. This is very useful to get a quick overview of all entries Often, we are interested in all files of a particular type. This can be done with the To find files with exactly the provided search pattern, use the Instead of just showing the search results, you often want to do something with them. The #### Examples Recursively find all zip archives and unpack them: Find all Any positional arguments after To see details like file permissions, owners, file sizes etc., you can tell The The terminal output of commands run from parallel threads using The For example, The syntax for generating commands is similar to that of GNU Parallel: - If you do not include a placeholder, fd automatically adds a #### Parallel vs. serial execution For Sometimes we want to ignore search results from a specific subdirectory. For example, we might fd If you want You may wish to include You can use There are scenarios where using fd β¦ -X rm -r This is the output of
run fd with a single argument: the search pattern. For example, assume that you want to find an
old script of yours (the name included netflix):
`` bashfd netfl
Software/python/imdb-ratings/netflix-details.pyIf called with just a single argument like this, fd searches the current directory recursivelynetfl
for any entries that contain the pattern .xRegular expression search
with and end with rc:cd /etc
fd '^x.*rc$'
X11/xinit/xinitrc
X11/xinit/xserverrcThe regular expression syntax used by fd is documented here.Specifying the root directory
fd passwd /etc
/etc/default/passwd
/etc/pam.d/passwd
/etc/passwdls -RList all files, recursively
in the current directory, recursively (similar to ):cd fd/tests
fd
testenv
testenv/mod.rs
tests.rsIf you want to use this functionality to list all files in a given directory, you have to use.
a catch-all pattern such as or ^:fd . fd/tests/
testenv
testenv/mod.rs
tests.rs-eSearching for a particular file extension
(or--extension) option. Here, we search for all Markdown files in the fd repository:cd fd
fd -e md
CONTRIBUTING.md
README.mdThe -e option can be used in combination with a search pattern:fd -e rs mod
src/fshelper/mod.rs
src/lscolors/mod.rs
tests/testenv/mod.rs-gSearching for a particular file name
(or --glob) option:fd -g libc.so /usr
/usr/lib32/libc.so
/usr/lib/libc.so-HHidden and ignored files
By default, fd does not search hidden directories and does not show hidden files in the
search results. To disable this behavior, we can use the (or --hidden) option:fd pre-commit
fd -H pre-commit
.git/hooks/pre-commit.sampleIf we work in a directory that is a Git repository (or includes Git repositories), fd does not.gitignore
search folders (and does not show files) that match one of the patterns. To disable-I
this behavior, we can use the (or --no-ignore) option:fd num_cpu
fd -I num_cpu
target/debug/deps/libnum_cpus-f5ce7ef99006aa05.rlibTo really search all files and directories, simply combine the hidden and ignore features to show-HI
everything () or use -u/--unrestricted.--full-pathMatching the full path
By default, fd only matches the filename of each file. However, using the or -p option,
you can match against the full path.fd -p -g '/.git/config'
fd -p '.*/lesson-\d+/[a-z]+.(jpg|png)'
fdCommand execution
-x
provides two ways to execute external commands for each of your search results:/--exec option runs an external command for each of the search results* (in parallel).-X
The /--exec-batch option launches the external command once, with all search results as arguments*.
fd -e zip -x unzipIf there are two such files, file1.zip and backup/file2.zip, this would executeunzip file1.zip and unzip backup/file2.zip. The two unzip processes run in parallel.h
(if the files are found fast enough). and .cpp files and auto-format them inplace with clang-format -i:
fd -e h -e cpp -x clang-format -iNote how the -i option to clang-format can be passed as a separate argument. This is why-x
we put the option last.-x belong to the command template, not to fd itself. If you-x
also want to pass a pattern or search path, put last:
fd pattern path -x echoFind all test_*.py files and open them in your favorite editor:
fd -g 'test_*.py' -X vimNote that we use capital -X here to open a single vim instance. If there are two such files,test_basic.py and lib/test_advanced.py, this will run vim test_basic.py lib/test_advanced.py.fd to show themls
by running for each result:
fd β¦ -X ls -lhd --color=alwaysThis pattern is so useful that fd provides a shortcut. You can use the -l/--list-detailsls
option to execute in this way: fd β¦ -l.-X option is also useful when combining fd with ripgrep (rg) in order to search within a certain class of files, like all C++ source files:
fd -e cpp -e cxx -e h -e hpp -X rg 'std::cout'Convert all .jpg files to .png files:
fd -e jpg -x convert {} {.}.pngHere, {} is a placeholder for the search result. {.} is the same, without the file extension.-x
See below for more details on the placeholder syntax. will not be interlaced or garbled,fd -x
so can be used to rudimentarily parallelize a task run over many files.
An example of this is calculating the checksum of each individual file within a directory.
fd -tf -x md5sum > file_checksums.txt#### Placeholder syntax-x and -X options take a command template as a series of arguments (instead of a single string).fd
If you want to add additional options to after the command template, you can terminate it with a \;.fd -x echo \; pattern path treats pattern path as fd arguments instead ofecho
passing them to . In practice, it is often clearer to write fd pattern path -x echo.{}: A placeholder token that will be replaced with the path of the search resultdocuments/images/party.jpg
().{.}
- : Like {}, but without the file extension (documents/images/party).{/}
- : A placeholder that will be replaced by the basename of the search result (party.jpg).{//}
- : The parent of the discovered path (documents/images).{/.}
- : The basename, with the extension removed (party).{} at the end.-x/--exec, you can control the number of parallel jobs by using the -j/--threads option.--threads=1
Use for serial execution.-HExcluding specific files or directories
want to search all hidden files and directories () but exclude all matches from .git-E
directories. We can use the (or --exclude) option for this. It takes an arbitrary glob
pattern as an argument:fd -H -E .git β¦
We can also use this to skip mounted directories:fd -E /mnt/external-drive β¦
.. or to skip certain file types:fd -E '*.bak' β¦
To make exclude-patterns like these permanent, you can create a .fdignore file. They work like.gitignore files, but are specific to fd. For example:cat ~/.fdignore
/mnt/external-drive
*.bakfd also supports .ignore files that are used by other programs such as rg or ag. to ignore these patterns globally, you can put them in fd's global ignore file.~/.config/fd/ignore
This is usually located in in macOS or Linux, and %APPDATA%\fd\ignore in.git/
Windows. in your fd/ignore file so that .git directories, and their contents--hidden
are not included in output if you use the option.fdDeleting files
to remove all files and directories that are matched by your search pattern.--exec-batch
If you only want to remove files, you can use the /-X option to call rm. For.DS_Store
example, to recursively remove all files, run:fd -H '^\.DS_Store$' -tf -X rm
If you are unsure, always call fd without -X rm first. Alternatively, use rms "interactive"
option:fd -H '^\.DS_Store$' -tf -X rm -i
If you also want to remove a certain class of directories, you can use the same technique. You willrm
have to use s --recursive/-r flag to remove directories.β¦/foo/bar/foo/β¦ can cause race conditions: if you have a
path like and want to remove all directories named foo, you can end up in afoo
situation where the outer directory is removed first, leading to (harmless) *"'foo/bar/foo':rm
No such file or directory"* errors in the call.fd -hCommand-line options
. To see the full set of command-line options, use fd --help which
also includes a much more detailed help text.
Usage: fd [OPTIONS] [pattern [path]...]
Arguments:
[pattern] the search pattern (a regular expression, unless '--glob' is used; optional)
[path]... the root directories for the filesystem search (optional)
Options:
-H, --hidden Search hidden files and directories
-I, --no-ignore Do not respect .(git|fd)ignore files
-s, --case-sensitive Case-sensitive search (default: smart case)
-i, --ignore-case Case-insensitive search (default: smart case)
-g, --glob Glob-based search (default: regular expression)
-a, --absolute-path Show absolute instead of relative paths
-l, --list-details Use a long listing format with file metadata
-L, --follow Follow symbolic links
-p, --full-path Search full abs. path (default: filename only)
-d, --max-depth <depth> Set maximum search depth (default: none)
-E, --exclude <glob> Exclude entries that match the given glob pattern
-t, --type <filetype> Filter by type: file (f), directory (d/dir), symlink (l),
executable (x), empty (e), socket (s), pipe (p), char-device
(c), block-device (b)
-e, --extension <ext> Filter by file extension
-S, --size <size> Limit results based on the size of files
--changed-within <date|dur> Filter by file modification time (newer than)
--changed-before <date|dur> Filter by file modification time (older than)
-o, --owner <user:group> Filter by owning user and/or group
--format <fmt> Print results according to template
-x, --exec <cmd>... Execute a command for each search result
-X, --exec-batch <cmd>... Execute a command with all search results at once
-c, --color <when> When to use colors [default: auto] [possible values: auto,
always, never]
--hyperlink[=<when>] Add hyperlinks to output paths [default: never] [possible
values: auto, always, never]
--ignore-contain <name> Ignore directories containing the named entry
-h, --help Print help (see more with '--help')
-V, --version Print version
Note that options can be given after the pattern and/or path as well.[0-9].jpgBenchmark
Let's search my home folder for files that end in
. It contains ~750.000find
subdirectories and about a 4 million files. For averaging and statistical analysis, I'm using
hyperfine. The following benchmarks are performed
with a "warm"/pre-filled disk-cache (results for a "cold" disk-cache show the same trends).Let's start with
:
Benchmark 1: find ~ -iregex '.*[0-9]\.jpg$'
Time (mean Β± Ο): 19.922 s Β± 0.109 s
Range (min β¦ max): 19.765 s β¦ 20.065 s
findis much faster if it does not need to perform a regular-expression search:
Benchmark 2: find ~ -iname '*[0-9].jpg'
Time (mean Β± Ο): 11.226 s Β± 0.104 s
Range (min β¦ max): 11.119 s β¦ 11.466 s
Now let's try the same forfd. Note thatfdperforms a regular expression-u
search by default. The options/--unrestrictedoption is needed here forfd
a fair comparison. Otherwisedoes not have to traverse hidden folders and
ignored paths (see below):
Benchmark 3: fd -u '[0-9]\.jpg$' ~
Time (mean Β± Ο): 854.8 ms Β± 10.0 ms
Range (min β¦ max): 839.2 ms β¦ 868.9 ms
For this particular example,fdis approximately 23 times faster thanfind -iregexfind -iname
and about 13 times faster than. By the way, both tools found the exactregex
same 546 files :smile:.Note: This is one particular benchmark on one particular machine. While we have
performed a lot of different tests (and found consistent results), things might
be different for you! We encourage everyone to try it out on their own. See
this repository for all necessary scripts.Concerning fd's speed, a lot of credit goes to the
andignorecrates that arefd
also used in ripgrep (check it out!).Troubleshooting
does not find my file!fdRemember that
ignores hidden directories and files by default. It also ignores patterns.gitignore
fromfiles. If you want to make sure to find absolutely every possible file, always-u
use the options/--unrestrictedoption (or-HIto enable hidden and ignored files):
fd -u β¦
Also remember that by default,fdonly searches based on the filename and-path
doesn't compare the pattern to the full path. If you want to search based on the
full path (similar to theoption offind) you need to use the--full-path-p
(or) option.fdColorized output
can colorize files by extension, just likels. In order for this to work, the environmentLS_COLORS
variablehas to be set. Typically, the valuedircolors
of this variable is set by thecommand which provides a convenient configuration formatLS_COLORS
to define colors for different file formats.
On most distributions,should be set already. If you are on Windows or if you are lookingfd
for alternative, more complete (or more colorful) variants, see here,
here or
here.also honors theNO_COLORenvironment variable.fddoesn't seem to interpret my regex pattern correctly[]A lot of special regex characters (like
,^,$, ..) are also special characters in your
shell. If in doubt, always make sure to put single quotes around the regex pattern:
fd '^[A-Z][0-9]+$'
If your pattern starts with a dash, you have to add--to signal the end of command line
options. Otherwise, the pattern will be interpreted as a command-line option. Alternatively,
use a character class with a single hyphen character:
fd -- '-pattern'
fd '[-]pattern'
alias"Command not found" for
es or shell functionsaliasShell
es and shell functions can not be used for command execution viafd -xorfd -X. Inzsh, you can make the alias global viaalias -g myalias="β¦". Inbash,export -f my_function
you can useto make available to child processes. You would stillfd -x bash -c 'my_function "$1"' bash
need to call. For other use cases or shells, usefzf
a (temporary) shell script.Integration with other programs
Using fd with
You can use fd to generate input for the command-line fuzzy finder fzf:
export FZF_DEFAULT_COMMAND='fd --type file'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
Then, you can typevim <Ctrl-T>on your terminal to open fzf and search through the fd-results..gitAlternatively, you might like to follow symbolic links and include hidden files (but exclude
folders):
export FZF_DEFAULT_COMMAND='fd --type file --follow --hidden --exclude .git'
You can even use fd's colored output inside fzf by setting:export FZF_DEFAULT_COMMAND="fd --type file --color=always"
export FZF_DEFAULT_OPTS="--ansi"
For more details, see the Tips section of the fzf README.rofiUsing fd with
fdrofi is a graphical launch menu application that is able to create menus by reading from stdin. Piping
output intorofis-dmenumode creates fuzzy-searchable lists of files and directories.$HOME#### Example
Create a case-insensitive searchable multi-select list of PDF files under your
directory and open the selection with your configured PDF viewer. To list all file types, drop the-e pdfargument.
fd --type f -e pdf . $HOME | rofi -keep-right -dmenu -i -p FILES -multi-select | xargs -I {} xdg-open {}
To modify the list that is presented by rofi, add arguments to thefdcommand. To modify the search behaviour of rofi, add arguments to theroficommand.emacsUsing fd with
find-file-in-projectThe emacs package find-file-in-project can
use fd to find files.After installing
, add the line(setq ffip-use-rust-fd t)to your~/.emacsor~/.emacs.d/init.elfile.M-x find-file-in-project-by-selectedIn emacs, run
to find matching files. Alternatively, runM-x find-file-in-projectto list all available files in the project.fdPrinting the output as a tree
To format the output of
as a file-tree you can use thetreecommand with--fromfile:
β― fd | tree --fromfile
This can be more useful than runningtreeby itself becausetreedoes notfd
ignore any files by default, nor does it support as rich a set of options asdoes to control what to print:
β― fd --extension rs | tree --fromfile
.
βββ build.rs
βββ src
βββ app.rs
βββ error.rs
On bash and similar you can simply create an alias:β― alias as-tree='tree --fromfile'
xargsUsing fd with
orparallelparallel')" title="Copy section prompt for LLMs"> Copy SectionfdNote that
has a builtin feature for command execution with-x
its/--execand-X/--exec-batchoptions. If you prefer, you can still usexargs
it in combination with:
fd -0 -e rs | xargs -0 wc -l
Here, the-0option tells fd to separate search results by the NULL character (instead of-0
newlines). In the same way, theoption ofxargstells it to read the input in this way.Installation

On Ubuntu
... and other Debian-based Linux distributions.If you run Ubuntu 19.04 (Disco Dingo) or newer, you can install the
officially maintained package:
apt install fd-find
Note that the binary is calledfdfindas the binary namefdis already used by another package.fd
It is recommended that after installation, you add a link toby executing commandln -s $(which fdfind) ~/.local/bin/fd, in order to usefdin the same way as in this documentation.$HOME/.local/bin
Make sure thatis in your$PATH..debIf you use an older version of Ubuntu, you can download the latest
package from the
release page and install it via:
dpkg -i fd_9.0.0_amd64.deb # adapt version number and architecture
Note that the .deb packages on the release page for this project still name the executablefd.On Debian
If you run Debian Buster or newer, you can install the
officially maintained Debian package:
apt-get install fd-find
Note that the binary is calledfdfindas the binary namefdis already used by another package.fd
It is recommended that after installation, you add a link toby executing commandln -s $(which fdfind) ~/.local/bin/fd, in order to usefdin the same way as in this documentation.$HOME/.local/bin
Make sure thatis in your$PATH.fdNote that the .deb packages on the release page for this project still name the executable
.fdOn Fedora
Starting with Fedora 28, you can install
from the official package sources:
dnf install fd-find
On Alpine Linux
You can install the fd package
from the official sources, provided you have the appropriate repository enabled:
apk add fd
On Arch Linux
You can install the fd package from the official repos:
pacman -S fd
You can also install fd from the AUR.On Gentoo Linux
You can use the fd ebuild from the official repo:
emerge -av fd
On openSUSE Linux
You can install the fd package from the official repo:
zypper in fd
fdOn Void Linux
You can install
via xbps-install:
xbps-install -S fd
On ALT Linux
You can install the fd package from the official repo:
apt-get install fd
On Solus
You can install the fd package from the official repo:
eopkg install fd
fdOn RedHat Enterprise Linux (RHEL) 8/9/10, Almalinux 8/9/10, EuroLinux 8/9 or Rocky Linux 8/9/10
You can install the
package from Fedora Copr.
dnf copr enable tkbcopr/fd
dnf install fd
A different version using the slower malloc instead of jemalloc is also available from the EPEL8/9 repo as the packagefd-find.fdOn macOS
You can install
with Homebrew:
brew install fd
β¦ or with MacPorts:port install fd
fdOn Windows
You can download pre-built binaries from the release page.
Alternatively, you can install
via Scoop:
scoop install fd
Or via Chocolatey:choco install fd
Or via Winget:winget install sharkdp.fd
On GuixOS
You can install the fd package from the official repo:
guix install fd
fdOn Mise
You can use mise to install
with a command like this:
mise use -g fd@latest
fdOn NixOS / via Nix
You can use the Nix package manager to install
:
nix-env -i fd
fdVia Flox
You can use Flox to install
into a Flox environment:
flox install fd
On FreeBSD
You can install the fd-find package from the official repo:
pkg install fd-find
From npm
On Linux and macOS, you can install the fd-find package:
npm install -g fd-find
From source
With Rust's package manager cargo, you can install fd via:
cargo install fd-find
Note that rust version 1.77.2 or later is required.makeis also needed for the build.muslFrom binaries
The release page includes precompiled binaries for Linux, macOS and Windows. Statically-linked binaries are also available: look for archives with
in the file name.Development
git clone https://github.com/sharkdp/fd
Build
cd fd
cargo build
Run unit tests and integration tests
cargo test
Install
cargo install --path .
.tar.gzCompletions
#### From Release Archives
Pre-built completion files are included in the release archives (
/.zip) on theautocomplete
Releases page, in thedirectory.fd.bash
To use these completions:- bash: Source the
file in your~/.bashrc, or place it in a directory that gets sourced automatically._fd
- zsh: Moveto a directory in yourfpath(e.g.,~/.zfunc).fd.fish
- fish: Copyto~/.config/fish/completions/._fd.ps1
- powershell: Sourcefrom one of your profile scripts.fd --gen-completions <shell>#### Generate from fd
You can also generate completions directly using
:
Bash
fd --gen-completions bash > ~/.local/share/bash-completion/completions/fd
Zsh (ensure ~/.zfunc is in your fpath)
fd --gen-completions zsh > ~/.zfunc/_fd
Fish
fd --gen-completions fish > ~/.config/fish/completions/fd.fish
PowerShell
fd --gen-completions powershell >> $PROFILE
`
Maintainers
- sharkdp
- tmccombs
- tavianator
License
fd` is distributed under the terms of both the MIT License and the Apache License 2.0.See the LICENSE-APACHE and LICENSE-MIT files for license details.