Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Feb 2009 09:48:14 -0600
From:      Dan Nelson <dnelson@allantgroup.com>
To:        t-u-t <marshc187@gmail.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: shell commands - exclusion
Message-ID:  <20090204154814.GR75802@dan.emsphone.com>
In-Reply-To: <332f78510902040635k6675a9b6u434879b42c66a579@mail.gmail.com>
References:  <332f78510902040635k6675a9b6u434879b42c66a579@mail.gmail.com>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
In the last episode (Feb 04), t-u-t said:
> 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}

zsh has the ^ and ~ glob metacharacters that are enabled with you enable
EXTENDED_GLOB:

       ^x     (Requires EXTENDED_GLOB to be set.)  Matches anything except
              the pattern x.  This has a higher precedence than `/', so
              `^foo/bar' will search directories in `.' except `./foo' for a
              file named `bar'.

       x~y    (Requires EXTENDED_GLOB to be set.)  Match anything that
              matches the pattern x but does not match y.  This has lower
              precedence than any operator except `|', so `*/*~foo/bar' will
              search for all files in all directories in `.' and then
              exclude `foo/bar' if there was such a match.  Multiple
              patterns can be excluded by `foo~bar~baz'.  In the exclusion
              pattern (y), `/' and `.' are not treated specially the way
              they usually are in globbing.
 
> and if there is, could the same be applied to other similar batch (?)
> operations, like pkg_delete -f "*" { except firefox3 wine thunderbird }
> etc..

That wildcard is expanded internally by pkg_delete using the C fnmatch()
function, which just does simple *?[] shell pattern matching.
 
> 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.
> 
> otherwise is it better to protect them with chflags or other trickery?

One workaround is to temporarily move the files you don't want to process
into another directory, then move them back when you're done.

-- 
	Dan Nelson
	dnelson@allantgroup.com



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?20090204154814.GR75802>