[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: which is the best way to find some files



On Δευ, 2011-12-26 at 01:18 +0800, lina wrote:
> On Monday 26,December,2011 01:13 AM, tony baldwin wrote:
> >> ----- Original Message -----
> >> From: lina
> >> Sent: 12/25/11 12:04 PM
> >> To: debian-user@lists.debian.org
> >> Subject: which is the best way to find some files
> >>
> >> Hi,
> >>
> >> I have some files like
> >>
> >> a_1.txt a_2.txt
> >> a_1.doc a_2.doc
> >> a_1.xxx a_2.xxx
> >>
> >> I only want to keep a_*.xxx
> >>
> >> but delete all other a_*.doc or .txt and more
> >>
> >> rm a_*.[^{xxx}] not work,
> >>
> >> Thanks for suggestions,
> >>
> >> Best regards,
> >>
> >>
> > maybe try
> >
> > rm !(*.xxx)
> Cool. work on my laptop,
> 
> but not on cluster:
> $ ls !(*.gro)
> -bash: !: event not found

Thanks, Lina! I did not know globs were so powerful.

>From `man bash`:
If the extglob shell option is enabled using the shopt builtin, several
extended  pattern  matching operators are recognized. In the following
description, a pattern-list is a list of one or more patterns separated
by a |.  Composite patterns may be formed using one or more of the
following sub-patterns:
	[...]
	!(pattern-list)
        Matches anything except one of the given patterns

So you will have to do: shopt -s extglob

Another alternative is to use the find command.

> Thanks,
> > ./tony
> > --
> > http://www.tonybaldwin.net
> > All Tony, all the time!
> >
> >
> 
> 



Reply to: