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 & exec for several regexp patterns together
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

find & exec for several regexp patterns together

Réponse
 
LinkBack Outils de la discussion
Vieux 19/03/2008, 16h15   #1
wong_powah@yahoo.ca
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut find & exec for several regexp patterns together

How to find & exec for several regexp patterns together?
e.g. How to combine the following commands into one command:
find . -name "*.aix" -exec rm {} \;
find . -name "*.sun*" -exec rm {} \;
find . -name "*.solaris*" -exec rm {} \;

I tried the following commands, but none of them work:
find . -name "(*.aix|*.sun*|*.solaris*)" -exec rm {} \;
find . -name "(*.aix\|*.sun*\|*.solaris*)" -exec rm {} \;
find . -name "\(*.aix|*.sun*|*.solaris*\)" -exec rm {} \;
find . -name "\(*.aix\|*.sun*\|*.solaris*\)" -exec rm {} \;



  Réponse avec citation
Vieux 19/03/2008, 16h47   #2
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find & exec for several regexp patterns together

wong_powah@yahoo.ca wrote:

> How to find & exec for several regexp patterns together?
> e.g. How to combine the following commands into one command:
> find . -name "*.aix" -exec rm {} \;
> find . -name "*.sun*" -exec rm {} \;
> find . -name "*.solaris*" -exec rm {} \;
>
> I tried the following commands, but none of them work:
> find . -name "(*.aix|*.sun*|*.solaris*)" -exec rm {} \;
> find . -name "(*.aix\|*.sun*\|*.solaris*)" -exec rm {} \;
> find . -name "\(*.aix|*.sun*|*.solaris*\)" -exec rm {} \;
> find . -name "\(*.aix\|*.sun*\|*.solaris*\)" -exec rm {} \;


See man find, operator "-o".

find \( -name "*.aix" -o -name "*.sun*" -o "*.solaris*" \) -exec rm {} \;

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
  Réponse avec citation
Vieux 19/03/2008, 16h49   #3
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find & exec for several regexp patterns together

pk wrote:

> find \( -name "*.aix" -o -name "*.sun*" -o "*.solaris*" \) -exec rm {} \;


Sorry, should have been

find \( -name "*.aix" -o -name "*.sun" -o name "*.solaris" \) -exec rm {} \;

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
  Réponse avec citation
Vieux 19/03/2008, 16h51   #4
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find & exec for several regexp patterns together

pk wrote:

> pk wrote:
>
>> find \( -name "*.aix" -o -name "*.sun*" -o "*.solaris*" \) -exec rm {} \;

>
> Sorry, should have been
>
> find \( -name "*.aix" -o -name "*.sun" -o name "*.solaris" \) -exec rm {}
> \;


>8-(


find \( -name "*.aix" -o -name "*.sun*" -o name "*.solaris*" \) -exec rm {}
\;

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
  Réponse avec citation
Vieux 19/03/2008, 20h59   #5
wong_powah@yahoo.ca
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find & exec for several regexp patterns together

On Mar 19, 11:51 am, pk <p...@pk.pk> wrote:
> pk wrote:
> > pk wrote:

>
> >> find \( -name "*.aix" -o -name "*.sun*" -o "*.solaris*" \) -exec rm {} \;

>
> > Sorry, should have been

>
> > find \( -name "*.aix" -o -name "*.sun" -o name "*.solaris" \) -exec rm {}
> > \;
> >8-(

>
> find \( -name "*.aix" -o -name "*.sun*" -o name "*.solaris*" \) -exec rm {}
> \;
>
> --
> All the commands are tested with bash and GNU tools, so they may use
> nonstandard features. I try to mention when something is nonstandard (if
> I'm aware of that), but I may miss something. Corrections are welcome.


Thank you very much.
A small typo - third regexp should be "-name":
find \( -name "*.aix" -o -name "*.sun*" -o -name "*.solaris*" \) -exec
rm {} \;
  Réponse avec citation
Vieux 19/03/2008, 21h30   #6
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find & exec for several regexp patterns together

wong_powah@yahoo.ca wrote:

> Thank you very much.
> A small typo - third regexp should be "-name":
> find \( -name "*.aix" -o -name "*.sun*" -o -name "*.solaris*" \) -exec
> rm {} \;


Yeah, a typo at last, since I hadn't done enough :-)

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
  Réponse avec citation
Vieux 20/03/2008, 06h07   #7
sgandotr@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find & exec for several regexp patterns together

On Mar 19, 8:15am, wong_po...@yahoo.ca wrote:
> How to find & exec for several regexp patterns together?
> e.g. How to combine the following commands into one command:
> find . -name "*.aix" -exec rm {} \;
> find . -name "*.sun*" -exec rm {} \;
> find . -name "*.solaris*" -exec rm {} \;
>
> I tried the following commands, but none of them work:
> find . -name "(*.aix|*.sun*|*.solaris*)" -exec rm {} \;
> find . -name "(*.aix\|*.sun*\|*.solaris*)" -exec rm {} \;
> find . -name "\(*.aix|*.sun*|*.solaris*\)" -exec rm {} \;
> find . -name "\(*.aix\|*.sun*\|*.solaris*\)" -exec rm {} \;



Try this -
find . \( -name "*.txt" -o -name "*.pl" -print \) -exec ls -l {} \;

  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 13h20.


É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,12746 seconds with 15 queries