sharkdp/fd · error · anyhow::Error
' ' is not a valid size constraint. See 'fd --help'.
Error message
'{}' is not a valid size constraint. See 'fd --help'. What it means
SizeFilter::from_string (filter/size.rs:30) requires the --size value to match the regex (?i)^([+-]?)(\d+)(b|[kmgt]i?b?)$. The optional sign selects Min (+) or Max (-); the unit must be one of b/k/m/g/t in SI or ki/mi/gi/ti binary forms. Anything not matching (e.g. bare number, bad unit, negative number without sign usage) yields this error.
Solutions
- Add a recognized unit: `fd --size 5k`, `fd --size +10m`, `fd --size -1g`, `fd --size 100b`.
- For 'larger than' prefix '+', for 'smaller than' prefix '-', for exact omit the sign.
- Use binary units if needed: `fd --size 1mi`, `fd --size 2gi`.
Example fix
# before fd --size 5 # after fd --size 5k # exactly 5 KB fd --size +10m # at least 10 MB fd --size -1g # less than 1 GB
Defensive patterns
Strategy: validation
Validate before calling
validate_size() {
# pattern: optional +/-, integer, unit b|k|ki|m|mi|g|gi|t|ti(+b)
printf '%s' "$1" | grep -Eq '^[+-]?[0-9]+(b|k|ki|m|mi|g|gi|t|ti)b?$' && fd --size "$1"
} Prevention
- Always include a unit; bare numbers are rejected.
- Use '+' for minimum and '-' for maximum; no sign means exact.
- Avoid decimal points; round to an integer magnitude.
When it happens
Trigger: Passing `fd --size 5` (no unit), `fd --size 5x`, `fd --size abc`, `fd --size 1.5k` (decimals not supported), or `fd --size kb` (missing magnitude). The regex requires an integer magnitude and a recognized unit.
Common situations: Forgetting the unit; using a decimal point; typing unsupported units like 'pb'/bytes-only with no suffix; confusing fd's syntax with du/find -size syntax.
Related errors
- ' ' is not a valid date or duration. See 'fd --help'.
- Malformed exclude pattern
- more than one ':' present in owner string
- Note: You can search for literal substrings with…
- A path separator must be exactly one byte, but the given…
AI-assisted analysis of sharkdp/fd@ee20f426dd (2026-08-09).
Data as JSON: /api/errors/0306286966815afd.
Report an issue: GitHub.
Appendix: source
Thrown at src/filter/size.rs:30
Equals(u64),
}
// SI prefixes (powers of 10)
const KILO: u64 = 1000;
const MEGA: u64 = KILO * 1000;
const GIGA: u64 = MEGA * 1000;
const TERA: u64 = GIGA * 1000;
// Binary prefixes (powers of 2)
const KIBI: u64 = 1024;
const MEBI: u64 = KIBI * 1024;
const GIBI: u64 = MEBI * 1024;
const TEBI: u64 = GIBI * 1024;
impl SizeFilter {
pub fn from_string(s: &str) -> anyhow::Result<Self> {
SizeFilter::parse_opt(s)
.ok_or_else(|| anyhow!("'{}' is not a valid size constraint. See 'fd --help'.", s))
}
fn parse_opt(s: &str) -> Option<Self> {
let pattern =
SIZE_CAPTURES.get_or_init(|| Regex::new(r"(?i)^([+-]?)(\d+)(b|[kmgt]i?b?)$").unwrap());
if !pattern.is_match(s) {
return None;
}
let captures = pattern.captures(s)?;
let limit_kind = captures.get(1).map_or("+", |m| m.as_str());
let quantity = captures
.get(2)
.and_then(|v| v.as_str().parse::<u64>().ok())?;
let multiplier = match &captures.get(3).map_or("b", |m| m.as_str()).to_lowercase()[..] {
v if v.starts_with("ki") => KIBI,
v if v.starts_with('k') => KILO,View on GitHub (pinned to ee20f426dd)