sharkdp/fd · error · anyhow::Error

The pattern(s) seems to only match files with a leading dot,

Error message

The pattern(s) seems to only match files with a leading dot, but hidden files are filtered by default. Consider adding -H/--hidden to search hidden files as well or adjust your search pattern(s).

What it means

Thrown by ensure_use_hidden_option_for_leading_dot_pattern in src/main.rs:531 on cfg(unix) when hidden filtering is on and one or more of the compiled pattern regexes can only match strings that start with a dot (e.g. '^\.bashrc' or '\.*'). fd hides dotfiles by default, so such a pattern would silently return nothing; fd surfaces the conflict instead.

Source

Thrown at src/main.rs:531

                "'{}' is not a valid date or duration. See 'fd --help'.",
                t
            ));
        }
    }
    Ok(time_constraints)
}

fn ensure_use_hidden_option_for_leading_dot_pattern(
    config: &Config,
    pattern_regexps: &[String],
) -> Result<()> {
    if cfg!(unix)
        && config.ignore_hidden
        && pattern_regexps
            .iter()
            .any(|pat| pattern_matches_strings_with_leading_dot(pat))
    {
        Err(anyhow!(
            "The pattern(s) seems to only match files with a leading dot, but hidden files are \
            filtered by default. Consider adding -H/--hidden to search hidden files as well \
            or adjust your search pattern(s)."
        ))
    } else {
        Ok(())
    }
}

fn build_regex(pattern_regex: String, config: &Config) -> Result<regex::bytes::Regex> {
    RegexBuilder::new(&pattern_regex)
        .case_insensitive(!config.case_sensitive)
        .dot_matches_new_line(true)
        .build()
        .map_err(|e| {
            anyhow!(
                "{}\n\nNote: You can search for literal substrings with '--fixed-strings' \
                 or literal strings with '--exact' options (instead of a regular expression). \

View on GitHub (pinned to 41532d114e)

Solutions

  1. Add -H/--hidden to include hidden files: 'fd -H "\.bashrc"'.
  2. Relax the regex so it can match non-dotfiles too (e.g. drop the leading-dot anchor).
  3. Combine with --no-ignore if the dotfile is also git-ignored: 'fd -H --no-ignore "\.env"'.

Example fix

// before
fd '\.bashrc'

// after
fd -H '\.bashrc'
Defensive patterns

Strategy: validation

Validate before calling

# if the regex can only match leading-dot names, force -H
if printf '%s' "$PAT" | grep -Eq '^(\^)?\\\.'; then
  fd -H "$PAT" "$@"
else
  fd "$PAT" "$@"
fi

Prevention

When it happens

Trigger: Running 'fd '\.bashrc'' or 'fd '.*'' without -H on Unix, with hidden filtering left at its default on.

Common situations: Searching for a dotfile config and forgetting hidden files are excluded; writing a regex anchored at '.' that cannot match any visible name.

Related errors


AI-assisted analysis of sharkdp/fd@41532d114e (2026-08-06). Data as JSON: /data/errors/29fd16f5c61623a8.json. Report an issue: GitHub.