Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

fd find files linux macos?

· 5 min read · Home Tech

In this article
  1. What is fd and Why Use It?
  2. Installation on Linux and macOS
  3. Basic Usage and Examples
  4. How fd Differs from find
  5. Advanced Options and Customization
  6. Common Issues and Troubleshooting
  7. Frequently Asked Questions

Yes, fd is a fast, user-friendly alternative to the traditional find command, and it works on both Linux and macOS. It is designed to be more intuitive, with sensible defaults like ignoring hidden files and respecting .gitignore, while still offering powerful search capabilities.

What is fd and Why Use It?

fd is a modern command-line tool written in Rust that simplifies file searching. It was created to address the complexity and verbosity of the classic find command. While find is incredibly powerful, its syntax can be cryptic for everyday tasks. fd provides a more straightforward approach: you type fd pattern and it searches the current directory recursively, showing results in a clean, colored output.

Key advantages include:

  • Speed: fd is parallelized and often faster than find for large directory trees.
  • Simple syntax: No need for -name or -type flags for basic searches; just provide the pattern.
  • Sensible defaults: Hidden files and directories (like .git) are ignored by default, as are entries in .gitignore files.
  • Regex support: Patterns are treated as regular expressions by default, but you can switch to glob-style matching with -g.

Installation on Linux and macOS

Installing fd is straightforward on both platforms.

macOS

The easiest way is via Homebrew:

brew install fd

If you prefer MacPorts, you can use:

sudo port install fd

Linux

Most distributions have fd in their repositories. For Debian/Ubuntu:

sudo apt install fd-find

Note that on Debian-based systems, the binary is named fdfind to avoid conflict with another package. You can create an alias: alias fd=fdfind in your shell configuration.

For Fedora:

sudo dnf install fd-find

For Arch Linux:

sudo pacman -S fd

If your distribution doesn't have it, you can download a precompiled binary from the GitHub releases page.

Basic Usage and Examples

Once installed, using fd is intuitive. Here are some common examples:

  • Find files by name: fd report — finds files or directories with "report" in the name.
  • Find by extension: fd -e txt — finds all .txt files.
  • Find directories only: fd -t d — lists only directories.
  • Find files only: fd -t f — lists only files.
  • Search in a specific directory: fd pattern /path/to/dir — searches in that directory.
  • Case-insensitive search: fd -i pattern — ignores case.
  • Execute a command on results: fd -e txt -x wc -l — counts lines in each text file.

The output is color-coded by file type, making it easy to scan.

How fd Differs from find

While find is a POSIX standard and available everywhere, fd offers a different philosophy. Here's a quick comparison:

Featurefindfd
Syntax for name searchfind . -name "*.txt"fd -e txt
Hidden filesIncluded by defaultIgnored by default (use -H to include)
Respects .gitignoreNoYes (use -I to ignore)
Regex supportLimited (via -regex)Full regex by default
Parallel executionNoYes

For simple searches, fd is faster to type and read. For complex, scripted operations, find remains powerful and portable.

Advanced Options and Customization

fd includes several advanced features that make it a versatile tool:

  • Exclude directories: fd -E node_modules — excludes a directory from the search.
  • Search for files by size: fd -s +10M — finds files larger than 10 MB.
  • Search by modification time: fd --changed-within 2d — finds files modified in the last 2 days.
  • Use glob patterns: fd -g '*.log' — uses glob-style matching instead of regex.
  • List all files including hidden: fd -H — shows hidden files and directories.
  • Ignore .gitignore: fd -I — includes ignored files.

You can also create aliases or wrapper functions in your shell to customize behavior. For example, to always show hidden files, add alias fd='fd -H' to your .bashrc or .zshrc.

Common Issues and Troubleshooting

Here are a few problems you might encounter and how to solve them:

  • Command not found: If you installed fd-find on Debian/Ubuntu, use fdfind instead, or create an alias.
  • No results when searching for a file: Remember that fd ignores hidden files and .gitignore by default. Use -H and -I to override.
  • Search is slow on large directories: Use -E to exclude large directories like node_modules or .git.
  • Want to search for an exact filename? Use -g with a glob pattern like fd -g 'exact.txt'.

Frequently Asked Questions

Is fd available on Windows?

Yes, fd is cross-platform and can be installed on Windows via choco install fd or by downloading the binary. However, this article focuses on Linux and macOS usage.

Can I use fd in scripts instead of find?

Yes, fd is script-friendly. It outputs results one per line, which works well with xargs or while read loops. However, if you need strict POSIX compliance, find is more portable.

Does fd support searching file contents?

No, fd only searches filenames. For content search, use grep or ripgrep (which is also written in Rust and pairs well with fd).

How do I update fd to the latest version?

If installed via a package manager, use the same manager to update (e.g., brew upgrade fd on macOS). For manual installs, download the new binary and replace the old one.

Why is fd faster than find?

fd uses parallel directory traversal and avoids stat calls on every file by default, which reduces overhead. It also stops early when it finds matches in some cases, though for full listings it still traverses everything.

Can I make fd the default find command?

You can create a shell alias like alias find=fd, but be aware that scripts expecting find syntax will break. It's safer to use fd explicitly.