PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > find files matching one of multiple patterns
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

find files matching one of multiple patterns

Réponse
 
LinkBack Outils de la discussion
Vieux 27/07/2007, 02h43   #1
wcyee
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut find files matching one of multiple patterns

Hi,

Is there an easier way to write this "find" expression to find any
files matching either *.bak or *.bck:

find . \( -name "*.bck" -o -name "*.bak" \) -print

Since all I want is really something like

ls *.{bak,bck}

but recursively over all subdirectories, I wonder if there's a way to
write a similar, shorter expression for the -name argument in find.

Thanks!

  Réponse avec citation
Vieux 27/07/2007, 02h54   #2
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find files matching one of multiple patterns

On Fri, 27 Jul 2007 01:43:48 +0000, wcyee wrote:

> Hi,
>
> Is there an easier way to write this "find" expression to find any files
> matching either *.bak or *.bck:
>
> find . \( -name "*.bck" -o -name "*.bak" \) -print
>
> Since all I want is really something like
>
> ls *.{bak,bck}
>
> but recursively over all subdirectories, I wonder if there's a way to
> write a similar, shorter expression for the -name argument in find.
>
> Thanks!


find . -name '*.b[ac]k' -print

  Réponse avec citation
Vieux 27/07/2007, 05h23   #3
wcyee
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find files matching one of multiple patterns

On Jul 26, 9:54 pm, Icarus Sparry <use...@icarus.freeuk.com> wrote:
> find . -name '*.b[ac]k' -print


That s - thanks much! What is the best way to find any files
matching a list of extensions, e.g.: "*.cpp", "*.c", "*.h", "*.pl" and
"*.sh"?

  Réponse avec citation
Vieux 27/07/2007, 06h32   #4
Seb
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find files matching one of multiple patterns

On 2007-07-27, wcyee <wcyeee@gmail.com> wrote:
> On Jul 26, 9:54 pm, Icarus Sparry <use...@icarus.freeuk.com> wrote:
>> find . -name '*.b[ac]k' -print

>
> That s - thanks much! What is the best way to find any files
> matching a list of extensions, e.g.: "*.cpp", "*.c", "*.h", "*.pl" and
> "*.sh"?


find . -iregex '.*\.\(foo\|bar\|baz\)$' -print


  Réponse avec citation
Vieux 27/07/2007, 08h34   #5
wcyee
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find files matching one of multiple patterns

On Jul 27, 1:32 am, Seb <s...@foo.com> wrote:
> On 2007-07-27, wcyee <wcy...@gmail.com> wrote:
>
> > On Jul 26, 9:54 pm, Icarus Sparry <use...@icarus.freeuk.com> wrote:
> >> find . -name '*.b[ac]k' -print

>
> > That s - thanks much! What is the best way to find any files
> > matching a list of extensions, e.g.: "*.cpp", "*.c", "*.h", "*.pl" and
> > "*.sh"?

>
> find . -iregex '.*\.\(foo\|bar\|baz\)$' -print


Nice. Thanks!

  Réponse avec citation
Vieux 27/07/2007, 10h23   #6
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find files matching one of multiple patterns

2007-07-27, 05:32(+00), Seb:
> On 2007-07-27, wcyee <wcyeee@gmail.com> wrote:
>> On Jul 26, 9:54 pm, Icarus Sparry <use...@icarus.freeuk.com> wrote:
>>> find . -name '*.b[ac]k' -print

>>
>> That s - thanks much! What is the best way to find any files
>> matching a list of extensions, e.g.: "*.cpp", "*.c", "*.h", "*.pl" and
>> "*.sh"?

>
> find . -iregex '.*\.\(foo\|bar\|baz\)$' -print

[...]

That's GNU (and possibly FreeBSD) specific. Even the regexp
syntax is not standard.

FreeBSD (and possibly other BSDs) also has a -E option for
extended regexps.

find -E . -iregex '.*\.(foo|bar|baz)$' -print

As a zsh user, I just do

print -rl -- **/*.(foo|bar|baz)

or to include dot files/dirs:
print -rl -- **/*.(foo|bar|baz)(D)

case insensitively:
print -rl -- **/*.(#i)(foo|bar|baz)(D)

The good thing is that you can replace print with any other
command.

--
Stéphane
  Réponse avec citation
Vieux 27/07/2007, 17h30   #7
wcyee
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find files matching one of multiple patterns

> As a zsh user, I just do
>
> print -rl -- **/*.(foo|bar|baz)
>
> or to include dot files/dirs:
> print -rl -- **/*.(foo|bar|baz)(D)
>
> case insensitively:
> print -rl -- **/*.(#i)(foo|bar|baz)(D)
>
> The good thing is that you can replace print with any other
> command.
>


Thanks. I've been meaning to check out zsh for quite some time. Your
examples are really neat.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h32.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14154 seconds with 15 queries