[Gllug] Match optional character in filename expansion with find
Stuart Sears
stuart at sjsears.com
Thu Feb 16 16:06:22 UTC 2012
On 16/02/12 15:10, John Edwards wrote:
> On Thu, Feb 16, 2012 at 02:57:21PM +0000, gvim wrote:
>> In the `find' command how do I match an optional end character, eg.
>> match all files ending in 'html' or 'htm'?
>>
>> find . -name '*.ht{m,ml}' -print
>>
>> ... doesn't work. Perl regexes have ? so what's the equivalent
>> using `find'.
>
> GNU find has a '-regex' option, but the man page says it only
> supports Emacs regular expressions and not Perl compatible ones.
>
You can specify the regex type you'd like to use - there are a number of
choices (at least on my version of findutils)
man find:
-regextype type
Changes the regular expression syntax understood by -regex and
-iregex tests which occur later on the command line. Currently-
implemented types are emacs (this is the default), posix-awk,
posix-basic, posix-egrep and posix-extended.
so something like this:
find . -type f -regextype posix-extended -iregex '.*\.html?'
but in this case even the standard 'emacs' regex class works the way you
want
find . -type f -regex '.*\.html?'
should probably do what you're after
n.b. these examples all from
find (GNU findutils) 4.5.10
Stuart
--
Stuart Sears RHCA etc.
"It's today!" said Piglet.
"My favourite day," said Pooh.
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list