- C 76.1%
- Shell 16.6%
- Roff 5%
- Makefile 1.9%
- Dockerfile 0.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| src | ||
| tests | ||
| .dockerignore | ||
| .gitignore | ||
| CHANGELOG.md | ||
| compose.yaml | ||
| Dockerfile | ||
| Makefile | ||
| nf.1 | ||
| README.md | ||
nf
nf is a fast, friendly replacement for find, written in C. You say what you
are looking for, and the common cases need no flags at all.
| Goal | find |
nf |
|---|---|---|
| Name contains "readme" | find . -iname '*readme*' |
nf readme |
| Files over 100 MB | find . -type f -size +100M |
nf -f --over 100M |
| Changed in the last 2 days | find . -mtime -2 |
nf --newer 2d |
| Several extensions | find . -type f \( -name '*.jpg' -o -name '*.png' \) |
nf -e jpg -e png |
| Exclude a folder | find . -path ./node_modules -prune -o -name '*.js' -print |
nf -e js --skip node_modules |
Search / without error spam |
find / -name foo 2>/dev/null |
nf foo / |
| Ten largest files | find . -type f -printf '%s %p\n' | sort -rn | head |
nf -f --sort size -n 10 |
| Run a command on the results | find . -name '*.log' -exec gzip {} + |
nf -e log -x gzip |
Install
You need a C compiler and make. There are no other dependencies.
make
sudo make install
This installs nf and its man page under /usr/local. Set PREFIX to change
that, for example make install PREFIX=~/.local.
To use it from Docker without installing anything:
docker compose build nf
SEARCH_DIR=~/projects docker compose run --rm nf readme
Usage
nf [PATTERN] [DIR...] [OPTIONS]
nf --help lists every option, and man nf explains them in more detail.
The first argument is always the pattern, and any more are folders to search.
With filters and no pattern, name the folder with --in:
nf --over 1G --in ~/Videos
Patterns
- Plain text matches anywhere in the name:
nf report *,?and[make it a glob, which must match the whole name:nf '*.c'-rmakes it a POSIX extended regex:nf -r '^test_.*\.py$'-Fkeeps it literal:nf -F '[draft]'
Case is ignored unless the pattern contains a capital letter. -i and -s
override that.
A / in the pattern matches against the path relative to the search folder
instead of the name. nf 'src/*.c' finds C files anywhere under any folder named
src, because * also matches / here. A leading / anchors the pattern to the
search folder.
Quote globs. Without quotes your shell expands *.c before nf sees it. nf
stops and tells you when this looks like what happened.
What is left out by default
- Hidden files and folders. Use
-ato include them. If a search in a terminal finds nothing but hidden files would have matched,nfsays so. /proc,/sysand similar virtual filesystems, unless you name them as the search folder./devis not left out, because it shares a filesystem type with real tmpfs mounts.- Whatever symbolic links point to. Use
--followto go through them. Links are never followed in circles.
.gitignore files are not read. Use --skip to leave things out.
nf crosses onto other filesystems by default, because btrfs subvolumes look like
separate filesystems and stopping there would hide /home on many systems.
--one-fs stays on one, and note that it does stop at a subvolume boundary.
Filters
--over and --under compare exact bytes. K, M, G and T mean powers of
1024, and KB, MB, GB and TB mean powers of 1000. -e, --over and
--under leave folders out unless you ask for them with -d.
--newer and --older take an age (30s, 30m, 2h, 3d, 2w, 6mo, 1y) or
a date (2026-01-31, 2026-01-31 14:00). They look at the modification time.
Output
Results print in whatever order the threads find them. --sort puts them in order,
but holds everything in memory and prints it all at the end.
Pipes get raw bytes, so use -0 with xargs -0 to survive unusual names. In a
terminal, control characters and invalid UTF-8 in names are shown as \xNN, so a
filename can't send escape codes to your terminal. Set NO_COLOR or use
--color never to turn colors off.
Running commands
Everything after -x belongs to the command, so -x goes last. Commands run one at
a time, after the search has finished and in sorted order, so they can't disturb
the search. Commands run directly, without a shell.
nf -e log -x gzip # paths appended, in batches
nf -e png -x convert {} {}.webp # once per result, {} replaced by the path
There is no --delete. Use nf ... -0 | xargs -0 rm, which is a step you have to
mean.
Exit status
| Status | Meaning |
|---|---|
| 0 | Something was found |
| 1 | Nothing was found |
| 2 | Bad arguments, a missing folder, an output failure, or a failed -x command |
Folders that can't be read don't change the exit status, or nf foo / would
always fail. They are counted on stderr, and --errors lists them.
Performance
Measured on one machine: 871,622 entries in a home folder, btrfs on NVMe, 8 cores,
warm cache, output to /dev/null, median of 7 runs. Cold-cache speed has not been
measured.
| Task | GNU find 4.10 | nf |
|---|---|---|
| List everything | 475 ms | 171 ms |
| Name contains "readme", any case | 602 ms | 150 ms |
Glob *.c |
567 ms | 155 ms |
| Over 1 MiB | 846 ms | 207 ms |
| Regex on the name | 2104 ms | 163 ms |
Run make bench to reproduce this. BENCH_ROOT picks the folder.
nf uses up to 8 threads because speed stopped improving there. -j changes that.
Development
make # build/nf
make test # unit, integration and differential tests
make lint # warnings as errors under gcc and clang
make asan # all tests under AddressSanitizer and UBSan
make tsan # all tests under ThreadSanitizer, needs clang
make valgrind # integration tests under valgrind
make bench # compare against GNU find
docker compose run --rm test runs the tests in a clean Debian image.
Layout:
| File | Purpose |
|---|---|
src/cli.c |
Command line parsing and validation |
src/parse.c |
Sizes and times |
src/pattern.c |
Text, glob and regex matching |
src/filter.c |
Type, extension, size and time filters |
src/walk.c |
Thread pool and directory traversal |
src/fstype.c |
Virtual filesystem detection, the one platform-specific file |
src/output.c |
Buffered output, colors, terminal escaping |
src/exec.c |
Running -x commands |
tests/differential.sh |
Compares results against GNU find on real folders |
tests/differential.sh is the safety net when changing the walker or filters.
DIFF_ROOTS picks which folders it compares.
Linux is the primary platform and the only one tested. The code uses readdir and
POSIX calls so that macOS and BSD ports stay possible, and src/fstype.c has an
untested branch for them.
Each thread keeps one open folder at a time and holds pending folders as heap
strings, so nf never runs out of file descriptors on wide or deep trees, and paths
longer than PATH_MAX work. Metadata is only read when a filter needs it. Name and
type checks are served from readdir alone, which is most of the speed advantage.