sharkdp/fd · error · anyhow::Error
The search pattern ' ' contains a path-separation character…
Error message
The search pattern '{pattern}' contains a path-separation character and will not lead to any search results.
If you want to search for all files inside the '{pattern}' directory, use a match-all pattern:
fd . '{pattern}'
Instead, if you want your pattern to match the full file path, use:
fd --full-path '{pattern}' What it means
Without --full-path, fd matches the pattern against the file name only, so any '/' in the pattern can never match and would silently yield zero results. ensure_single_search_pattern_is_not_a_path (main.rs:185) detects this and returns a helpful error instead. On Windows, '\' is also flagged but only when the pattern resolves to an existing directory, since '\' is also the regex escape char. This applies to the primary pattern and every --and pattern.
Solutions
- Search by file name only: `fd foo` instead of `fd /home/user/foo`.
- To list everything under a directory, use a match-all pattern: `fd . /home/user/foo`.
- To match against the full path, add --full-path: `fd --full-path /home/user/foo`.
Example fix
# before fd /home/user/src # after (list contents of that dir) fd . /home/user/src # or match full paths fd --full-path home/user/src
Defensive patterns
Strategy: validation
Validate before calling
if printf '%s' "$PATTERN" | grep -q '/'; then # pattern is a path; pass it as a search path instead fd . "$PATTERN" else fd "$PATTERN" fi
Prevention
- Search by file name, not full path, unless using --full-path.
- Validate user-supplied patterns for '/' before passing to fd.
- Use `fd . <dir>` to list a directory's contents.
When it happens
Trigger: Running `fd /home/user/foo`, `fd src/main.rs`, or `fd --and lib/utils`. The cheap '/' check always flags it; on Windows the '\' branch additionally requires Path::new(pattern).is_dir().
Common situations: Pasting a full path instead of a file name; muscle memory from `find path`; scripts that interpolate full paths into the pattern position.
Related errors
- A path separator must be exactly one byte, but the given…
- Note: You can search for literal substrings with…
- The pattern(s) seems to only match files with a leading…
- Could not retrieve current directory (has it been deleted?).
- 'fd --list-details' is not supported on this platform.
AI-assisted analysis of sharkdp/fd@ee20f426dd (2026-08-09).
Data as JSON: /api/errors/f90bc0e7b92d164e.
Report an issue: GitHub.
Appendix: source
Thrown at src/main.rs:204
// Start with the cheap check: '/' is always a path separator, including on
// Windows, and has no regex meaning, so flagging it is safe and catches the
// Linux/macOS mistake of pasting a full path as the pattern.
#[cfg_attr(not(windows), allow(unused_mut))]
let mut should_warn = pattern.contains('/');
// On Windows we additionally accept the native `\` separator, but only when
// the pattern actually resolves to an existing directory - `\` is also the
// regex escape char there, so valid patterns like `\Ac` or `\d+` must still
// run. The is_dir syscall is only needed when `should_warn` is still false,
// so short-circuit via `||` to avoid the stat call on the happy path.
#[cfg(windows)]
{
should_warn = should_warn
|| (pattern.contains(std::path::MAIN_SEPARATOR) && Path::new(pattern).is_dir());
}
if should_warn {
Err(anyhow!(
"The search pattern '{pattern}' contains a path-separation character \
and will not lead to any search results.\n\n\
If you want to search for all files inside the '{pattern}' directory, use a match-all pattern:\n\n \
fd . '{pattern}'\n\n\
Instead, if you want your pattern to match the full file path, use:\n\n \
fd --full-path '{pattern}'",
pattern = pattern,
))
} else {
Ok(())
}
}
fn build_pattern_regex(pattern: &str, opts: &Opts) -> Result<String> {
Ok(if opts.glob && !pattern.is_empty() {
let glob = GlobBuilder::new(pattern).literal_separator(true).build()?;
glob.regex().to_owned()
} else if opts.exact {View on GitHub (pinned to ee20f426dd)