LinuxCommandLibrary

fd

Find entries in your filesystem

TLDR

Recursively find files matching a specific pattern in the current directory

$ fd "[string|regex]"
copy

Find files that begin with a specific string
$ fd "[^string]"
copy

Find files with a specific extension
$ fd [[-e|--extension]] [txt]
copy

Find files in a specific directory
$ fd "[string|regex]" [path/to/directory]
copy

Include ignored and hidden files in the search
$ fd [[-H|--hidden]] [[-I|--no-ignore]] "[string|regex]"
copy

Execute a command on each search result returned
$ fd "[string|regex]" [[-x|--exec]] [command]
copy

SYNOPSIS

fd [options] [pattern] [path...]

PARAMETERS

--help, -h
    Show help message.

--version, -V
    Show version information.

--hidden, -H
    Search hidden files and directories (those starting with a dot).

--no-ignore, -I
    Do not respect .gitignore, .ignore, or .fdignore files.

--case-sensitive, -s
    Perform a case-sensitive search. Overrides smart-case and --ignore-case.

--ignore-case, -i
    Perform a case-insensitive search. Overrides smart-case.

--glob, -g
    Interpret the pattern as a glob pattern instead of a regular expression.

--extension, -e
    Filter by file extension. Can be used multiple times (e.g., -e txt -e md).

--type, -t
    Filter by file type. Types include: f (file), d (directory), l (symlink), s (socket), p (pipe), b (block device), c (char device).

--exec, -x
    Execute a command for each search result. The placeholder {} is replaced by the path of the found entry. For example: fd .txt -x cat.

--exec-batch, -X
    Execute a command once, passing all search results as arguments. The placeholder {} is replaced by all found paths. More efficient for commands that can handle multiple inputs.

--max-depth, -d
    Set the maximum search depth from the starting path.

--min-depth, -m
    Set the minimum search depth from the starting path.

--full-path, -p
    Display the full path of the search results instead of just the file name.

--follow, -L
    Follow symbolic links.

--color, -c
    Control color output. Values: auto (default), always, never.

--size, -S <+|-|=size>
    Filter by size. Examples: +1M (greater than 1MB), -500K (less than 500KB), =2G (exactly 2GB).

--owner, -o
    Filter by owner and/or group. Examples: john:staff, :users.

--changed-within, -D
    Filter by modification time. Examples: 2023-01-01, 2weeks, 3days ago.

--exclude, -E
    Exclude files/directories that match the given pattern. Can be used multiple times. Patterns are treated as regular expressions by default.

--prune
    Do not descend into directories that match an exclude pattern.

--threads, -j
    Set the number of worker threads to use. Defaults to the number of CPU cores.

DESCRIPTION

fd is a program to find entries in your filesystem, built as a modern, user-friendly, and significantly faster replacement for the traditional find utility. Written in Rust, it leverages Rust's performance capabilities to deliver search results quickly, especially on large directories.

Key features that differentiate fd include a simpler, more intuitive syntax compared to find, smart case-sensitive searching (case-sensitive if the pattern contains uppercase letters, otherwise insensitive), and colorized output by default for better readability. It intelligently ignores hidden files and directories, as well as patterns specified in .gitignore, .ignore, and .fdignore files by default, making daily searches less cluttered.

fd supports regular expressions for powerful pattern matching, but also offers a glob mode. It can filter results by file type (files, directories, symlinks), extension, size, and modification date. Furthermore, fd includes robust options to execute commands on the found search results, either individually or in batches, similar to find's -exec option, but with a more straightforward syntax. Its focus on speed and ease of use makes it a popular choice for developers and system administrators.

CAVEATS

While fd aims to be a modern replacement for find, it is not a complete drop-in substitute for all find use cases. It simplifies many common operations but might lack the exhaustive set of options for extremely niche or complex filesystem attribute queries that find offers. Its default behavior of ignoring hidden files and .gitignore patterns, while convenient, can sometimes be unexpected for users accustomed to find's default inclusiveness, requiring the use of -H or -I flags.

DEFAULT BEHAVIOR & SMART-CASE

fd has several user-friendly defaults. By default, it ignores hidden files and directories (those starting with a dot) and files/directories specified in .gitignore, .ignore, or .fdignore files. The search pattern is treated as a regular expression.

The 'smart-case' feature is enabled by default: if your search pattern contains any uppercase characters, the search becomes case-sensitive. Otherwise, it remains case-insensitive. This behavior can be overridden using the --case-sensitive (-s) or --ignore-case (-i) flags.

EXECUTION WITH <B>-X</B> AND <B>-X</B>

fd's -x (--exec) and -X (--exec-batch) options provide powerful ways to act on search results. -x executes the specified command for each found file, replacing {} with the file's path. For example, fd .txt -x cat would display the content of each found .txt file.

-X executes the command only once, passing all found files as arguments to the command. This is more efficient for commands that can handle multiple inputs. For example, fd .txt -X rm would remove all found .txt files in one rm call.

HISTORY

fd was created by David Herges and first released in 2017. It was developed in Rust with the explicit goal of providing a faster and more intuitive alternative to the long-standing find command. Its adoption grew rapidly due to its performance benefits and user-friendly design, quickly becoming a preferred tool for file searching in many development and system administration workflows. The project continues to be actively maintained and improved, integrating new features while retaining its core principles of speed and simplicity.

SEE ALSO

find(1), grep(1), ls(1)

Copied to clipboard