I have some images named with generated uuid1 string. For example 81397018-b84a-11e0-9d2a-001b77dc0bed.jpg. I want to find out all these images using "find" command:
find . -regex "[a-f0-9\-]\{36\}\.jpg".
But it doesn't work. Something wrong with the regex? Could someone help me with this?
Try to use single quotes (') to avoid shell escaping of your string. Remember that the expression needs to match the whole path, i.e. needs to look like:
Apart from that, it seems that my find (GNU 4.4.2) only knows basic regular expressions, especially not the {36} syntax. I think you'll have to make do without it.
Judging from other answers, it seems this might be find's fault.
However you can do it this way instead:
find . * | grep -P "[a-f0-9\-]{36}\.jpg"
You might have to tweak the grep a bit and use different options depending on what you want but it works.
on Mac (BSD find): Same as accepted answer, the
.*/
prefix is needed to match a complete path:man find
says-E
uses extended regex supportNote that you need to specify
.*/
in the beginning becausefind
matches the whole path.Example:
My version of find:
You should use absolute directory path when applying find instruction with regular expression. In your example, the
should be changed into
In most Linux systems, some disciplines in regular expression cannot be recognized by that system, so you have to explicitly point out -regexty like
The
-regex
find expression matches the whole name, including the relative path from the current directory. Forfind .
this always starts with./
, then any directories.Also, these are
emacs
regular expressions, which have other escaping rules than the usual egrep regular expressions.If these are all directly in the current directory, then
should work. (I'm not really sure - I can't get the counted repetition to work here.) You can switch to egrep expressions by
-regextype posix-egrep
:(Note that everything said here is for GNU find, I don't know anything about the BSD one which is also the default on Mac.)