A Comprehensive Guide to Using the fd File Search Tool
This article introduces the open‑source, Rust‑based command‑line utility fd, explains how to install it on various platforms, and demonstrates a wide range of search options—including hidden files, case sensitivity, depth limits, file‑type filtering, and exec commands—providing a practical tutorial for efficient file searching.
This article is part of HelloGitHub’s "Explaining Open‑Source Projects" series and presents fd, a fast, user‑friendly alternative to the Unix find command written in Rust.
1. fd Overview
fd is a cross‑platform command‑line tool that offers colorful output and powerful search capabilities. It is built with Rust, giving it performance comparable to C++ while providing a modern, ergonomic interface.
2. Installing fd
fd can be installed via package managers on macOS, Linux, and Windows, or built from source using Cargo.
2.1 One‑click installation (Homebrew)
$ brew install fdUpgrade with:
$ brew upgrade fd2.2 Building from source
$ git clone https://github.com/sharkdp/fd.git
$ cd fd
$ cargo install --path .2.3 Viewing help
After installation, run fd -h or fd --help to see usage information.
$ fd -h
fd 8.2.1
USAGE:
fd [FLAGS/OPTIONS] [
] [
...]
FLAGS:
-H, --hidden Search hidden files and directories
-I, --no-ignore Do not respect .gitignore files
-s, --case-sensitive Enforce case‑sensitive matching
-i, --ignore-case Ignore case (smart case by default)
-F, --fixed-strings Treat pattern as a literal string
-a, --absolute-path Show absolute paths
-L, --follow Follow symlinks
-p, --full-path Search the full path
-0, --print0 Separate results with a null character
-h, --help Print help information
-V, --version Print version information
OPTIONS:
-d, --max-depth
Set maximum search depth
-t, --type
... Filter by file type (f, d, l, x, e, s, p)
-e, --extension
... Filter by file extension
-x, --exec
... Execute a command for each result
-E, --exclude
... Exclude entries matching a glob pattern
-c, --color
When to use color (never, auto, always)
-j, --threads
Number of threads to use
-S, --size
... Filter by file size
...3. Quick Start Demonstrations
A sample directory structure is created to illustrate various fd commands.
.
├── .hg
│ ├── HelloDjango.md
│ ├── HelloRust.md
│ ├── HelloVue.md
│ └── HelloZooKeeper.md
├── dir1
│ ├── Hello.java
│ ├── World.java
│ └── dir2
│ ├── demo.py
│ ├── demo1.py
│ ├── dir3
│ │ ├── fd_demo.rs
│ │ └── fd_help.rs
│ └── sss.py
├── hello_fd.md
├── hello_java.md
├── java
│ ├── Hello.java
│ └── World.java
├── my_java.txt
├── python
│ ├── demo.py
│ ├── demo1.py
│ └── sss.py
└── rust
├── fd_demo.rs
└── fd_help.rs3.1 Simple search
$ fd Hello
dir1/Hello.java
java/Hello.java3.2 Include hidden files
$ fd -H Hello
.hg/HelloDjango.md
.hg/HelloRust.md
.hg/HelloVue.md
.hg/HelloZooKeeper.md
dir1/Hello.java
java/Hello.java3.3 Case handling
$ fd -i Hello
dir1/Hello.java
hello_fd.md
hello_java.md
java/Hello.java $ fd -s hello
hello_fd.md
hello_java.md3.4 Absolute paths
$ fd -a Hello
/Users/junjiexun/fd_test/dir1/Hello.java
/Users/junjiexun/fd_test/java/Hello.java3.5 List details
$ fd -l hello
-rw-r--r-- 1 junjiexun staff 0B 3 1 18:42 dir1/Hello.java
-rw-r--r-- 1 junjiexun staff 0B 3 1 18:37 hello_fd.md
...3.6 Search full path
$ fd -p xun
dir1
dir1/Hello.java
...3.7 Include .gitignore files
$ fd -I java
dir1/Hello.java
...4. Advanced Search Options
4.1 Depth limit
$ fd -d 3 rs
rust/fd_demo.rs
rust/fd_help.rs4.2 File type filtering
$ fd -t l
softdir3
sss.py4.3 Extension filtering
$ fd -e md
hello_fd.md
hello_java.md4.4 Excluding patterns
$ fd -E '*s*'
(dir1 and other entries without 's' in their names)4.5 Owner filtering
$ fd -l -o junjiexun
drwxr-xr-x 5 junjiexun staff 160B 3 1 18:42 dir1
...4.6 Executing commands on results
$ fd java -X rm -rf # dangerous, for demo only
$ fd py -X vim4.7 Regular expressions and glob patterns
$ fd '^s.*'
(dir1/dir2/sss.py, python/sss.py, softdir3, sss.py) $ fd -g 's*'
(dir1/dir2/sss.py, python/sss.py, softdir3, sss.py)5. Conclusion
fd is a simple, fast, and user‑friendly command‑line file search tool; its open‑source nature and Rust implementation make it an excellent example for learning system‑level programming while greatly improving everyday search workflows.
IT Services Circle
Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.