Note that [100-999]
is equal to [0-9]
, and your regex requires the file name to only contain one or more digits. Also, you missed the colons in the POSIX character class definition, [[digit]]
must look like [[:digit:]]
if you plan to match a digit in the glob -name
pattern.
If you want to find files with name starting with 3 digits (and then there can be anything, including more digits) you can use
find . -type f -name '[[:digit:]][[:digit:]][[:digit:]]*'
find . -type f -name '[0-9][0-9][0-9]*'
find . -type f -regextype posix-extended -regex '.*/[0-9]{3}[^/]*$'
Note:
find . -type f -name '[[:digit:]][[:digit:]][[:digit:]]*'
or find . -type f -name '[0-9][0-9][0-9]*'
- here, the name "pattern" is a glob pattern that matches the entire file name and thus it must start with 3 digits and then *
wildcard matches any text till the file name end
find . -type f -regextype posix-extended -regex '.*/[0-9]{3}[^/]*$'
- if you prefer to play with regex, or extend in the future - it matches any text till last /
and then 3 digits and any text other than /
till the end of string.
If there can be only three and not four digits at the start, you need
find . -type f -regextype posix-extended -regex '.*/[0-9]{3}([^0-9][^/]*)?$'
Here,
.*/
- matches up to the last /
char including it
[0-9]{3}
- any three digits
([^0-9][^/]*)?
- an optional occurrence of a non-digit and then zero or more chars other than a /
$
- end of string.