shell commands - exclusion

William Gordon Rutherdale will.rutherdale at utoronto.ca
Wed Feb 4 19:38:02 PST 2009


Lars Eighner wrote:
> 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. . . .
Oh yes it is, it is very easy.  I've done things like this in unix 
environments for years.  I also apply it to tar commands all the time.

All you have to do is this:

$ ls >rm.in
$ vi rm.in
   . . . edit out all the files you don't want to erase . . .
$ rm `cat rm.in`

-Will




More information about the freebsd-questions mailing list