Bash find command with REGEX quantifiers
Using REGEX quantifiers with the find command
For example, in the following example I am lokking in the /movoes/
directory for all movies with a quality suffix, (e.g. /movies/a/Avengers - Endgame (2019) [HC].mp4
)
find /movies/ -type f -regextype grep -regex '.*\[.\{1,4\}\].*'
Notes
- The single quotes
'
around the entire REGEX pattern are required! - The initial
.*
and final.*
are required!. This is because the pattern is applied to the entire line, or in this case, the full path, returned byfind
- The square brackets
[
and]
and the curly brackets{
and}
are all escaped with a single\
to ensure they are passed to REGEX from bash. - The
--regextype grep
ensures the REGEX quantifier syntax is supported. The default GNUfind
does not support the\{from,to\}
syntax.--regextype sed
among other types, will also work.