Skip to main content

Find vs. Locate vs. Fd

While find is the undisputed heavyweight champion of filesystem traversal, it is not always the best tool for every job. Depending on the environment and the goal, alternative tools might offer better performance or ergonomics.

Here is a professional breakdown of when to use find versus its primary alternatives: locate and fd.

1. The find Command

The Uncompromising Workhorse

find queries the live filesystem in real-time. It reads the actual inodes and directory structures at the exact moment of execution.

  • Pros:
    • 100% Accurate: Reflects the absolute current state of the filesystem.
    • Ubiquitous: Installed on every Unix/Linux system by default.
    • Powerful Actions: Capable of executing complex commands (-exec) directly on results.
    • Deep Filtering: Can query obscure metadata (e.g., octal permissions, SUID bits).
  • Cons:
    • Slow on Massive Disks: Must perform heavy I/O to read millions of directories.
    • Complex Syntax: Notoriously pedantic expression grammar.

Best Use Case: Scripting, system administration, auditing, automated cleanup, and anytime you need 100% guarantee that the file exists right now.


2. The locate Command

The Database Indexer

locate (and its modern variant mlocate or plocate) does not read the live filesystem. Instead, it queries a pre-built database (usually updated nightly via a cron job running the updatedb command).

  • Pros:
    • Instantaneous: Returns results in milliseconds, even on drives with millions of files.
    • Simple Syntax: locate [keyword] is all you need.
  • Cons:
    • Stale Data: Will not find files created after the last updatedb run.
    • Ghost Files: Will list files that have been deleted since the last updatedb run.
    • Limited Filtering: Only searches by file path/name. Cannot filter by size, time, or permissions.

Best Use Case: Rapidly finding a known file on a personal workstation or finding system binaries when you forget their absolute path (e.g., locate php.ini).


3. The fd Command

The Modern Developer Tool

fd is a modern alternative written in Rust. It aims to fix the UX issues of find while maintaining high performance. It uses parallel directory traversal to achieve extreme speeds.

  • Pros:
    • Extremely Fast: Often significantly faster than find due to multi-threading.
    • Developer Friendly: Smart case sensitivity, colorized output, and regular expressions by default.
    • Git-Aware: Automatically respects .gitignore and .fdignore files, skipping build directories and node_modules automatically.
    • Simple Syntax: fd pattern instead of find . -name "*pattern*".
  • Cons:
    • Not Default: Must be manually installed (apt install fd-find or via cargo).
    • Not POSIX: Cannot be relied upon in portable shell scripts.
    • Less Granular: Lacks some of the ultra-specific, low-level metadata flags of find.

Best Use Case: Interactive use by developers navigating project source code, refactoring, and everyday terminal usage on modern workstations.

Summary Matrix

Featurefindlocatefd
Search MechanismLive FilesystemPre-built DatabaseLive Filesystem (Parallel)
SpeedModerate (I/O Bound)Instant (DB Query)Extremely Fast (CPU/IO)
Accuracy100% Real-timeStale (Nightly)100% Real-time
Syntax UXPoor / ComplexExcellent / SimpleExcellent / Intuitive
Respects .gitignoreNoNoYes
Available by DefaultYes (Everywhere)Yes (Most Distros)No (Requires Install)