I was trying to find files in a certain directory which don't adhere to the naming guidelines for UNIX-like systems.
When using with find the command find <dir> -regex '.*[^-_./0-9a-zA-Z].*'
returns the files of interest.
my question with above command line is:
- Why did we need the any one character metacharacter
.
before the zero or more*
metacharacter at the start and end of the regex respectively for this to work as intended. when i initially tried withfind <dir> -regex '*[^-_./0-9a-zA-Z]*'
that returned nothing. - Furthermore, if I replace the
character ranges
in the regex with their correspondingPOSIX character classes
with everything else intact:find <dir> -regex '.*[^-_./[:digit:][:lower:][:upper:]].*'
it returns nothing. why is it this way?
TIA!
-regex
? It matches over the whole path. – muru Aug 08 '20 at 09:57/
, the path separator, in what system do you think your regex will match a whole path? – muru Aug 08 '20 at 12:01.
which matches anything, and explicitly exclude/
, which is the path separator, of course you're excluding the path separator. I have no idea what your random bolding is meant to imply. – muru Aug 08 '20 at 13:52.
and don't explicitly exclude the/
, the resulting regex*[^-_.0-9a-zA-Z]*
won't work then either, will it?.
has to be included not just because of the path separator. My misconception here was cleared pretty nicely by @steeldriver. The regex won't work without the leading and trailing.
because then the quantifier*
isn't specifying what it wants to have none or more of. It was a misconception because I was mixing up the shell wildcard*
with the regex quantifier*
... – computronium Aug 08 '20 at 15:14-regex
matches against the full path) – ilkkachu Aug 08 '20 at 16:44find . ! -regex '[-_./0-9a-zA-Z]*'
, if that's any clearer – ilkkachu Aug 08 '20 at 16:58