Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Feb 2009 09:26:10 -0600 (CST)
From:      Lars Eighner <>
To:        t-u-t <>
Subject:   Re: shell commands - exclusion
Message-ID:  <20090204091459.G16842@qroenaqrq.6qbyyneqvnyhc.pbz>
In-Reply-To: <>
References:  <>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
On Wed, 4 Feb 2009, t-u-t wrote:

> hi, i don't know if this is a freak question, but i was looking around to
> see if this is possible, and what the convention would be.
> if i have say one (or even two) single file/directories among many others,
> and i want to perform any said function like cp, mv, rm, etc.. , to all
> other files except that one or two, is there a way to do that in a single
> command?
> e.g
> rm -r * {-except foo1 foo15}

In general this is not possible.  A few commands have exclusion options, but
not many.  Some shells have ways of managing glob exclusion (it's the shell
that expands wildcard patterns).  Setting GLOBIGNORE works in BASH, whether
something similar works in others, you will have to investigate yourself. 
But that isn't one line as you have to set GLOBIGNORE.  BASH also has an
extended pattern matching option which includes negation, so you might want
to look into that.

> and if there is, could the same be applied to other similar batch (?)
> operations, like pkg_delete -f "*" { except firefox3 wine thunderbird }
> etc..

pkg_delete can take regular expression arguments (see -x).  Perhaps you
can devise one that will do the trick.  Beware, however: it can take
multiple regular expressions and deletes package which match ANY (not all)
of them.

> i'm a bit new to the shell (took me a while to figure out *ls* and *ls |
> more*), but i can't find anything from google cuz i don't know what this
> would be called in the first place.

Shell globbing is the operation by which the shell expands wildcards and
finds matches.  What you want to do exclude things from shell globbing.

> otherwise is it better to protect them with chflags or other trickery?

watch out anything involving recursion --- things can happen that you don't
expect unless you really know what you are doing.

Lars Eighner
8800 N IH35 APT 1191 AUSTIN TX 78753-5266

Want to link to this message? Use this URL: <>