[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: find / -iregex not working as expected
From: |
Eric Blake |
Subject: |
Re: find / -iregex not working as expected |
Date: |
Thu, 12 Nov 2015 10:07:26 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
On 11/12/2015 08:41 AM, Michael Convey wrote:
> I'm trying to find the following files with a single 'find' statement:
>
> /var/lib/postgresql/9.4/main/postgresql.auto.conf
> /usr/lib/tmpfiles.d/postgresql.conf
> /etc/postgresql/9.4/main/postgresql.conf
>
> I tried the following (and more), but I can't figure it out:
>
> find / -iregex "*postgresql.*.conf"
This says find all files that match the case-insensitive regular
expression "*postgresql.*.conf". A regex of ".*." is identical to a
regex of ".+" (1 or more arbitrary characters), and NOT the same as a
regular expression for a literal '.'. A leading "*" in a regular
expression is unspecified behavior, but many regex engines treat it
identically to a regex of "\*" (matching only a literal '*'). As your
desired filenames do not start with a literal star, the regex won't
match them.
> find / -iregex "*/postgresql*.conf"
Still a literal star issue.
> find / -iregex *postgresql*.conf
Here, you lack shell quoting, so your shell tries to glob the '*' before
even passing the argument to find. Generally not what you want.
> find / -iregex '*postgresql.*.conf'
This is no different than your first attempt (changing between '' and ""
shell quoting doesn't affect the string seen by find).
What you probably want is to use '-iname', not '-regex', for a
case-insensitive glob comparison. As in:
find / -iname 'postgresql.*conf'
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature