shell commands - exclusion

Chris Whitehouse cwhiteh at onetel.com
Thu Feb 5 16:55:30 PST 2009


Jaime wrote:
> On Wed, Feb 4, 2009 at 9:35 AM, t-u-t <marshc187 at gmail.com> wrote:
> 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}

I think you should be able to do it with a combination of -prune and 
-delete (or -exec rm -rf {} \; ) on a find command. Substitute your 
other commands for rm -rf in the -exec above.

I would give you a working example except I can't figure out the syntax 
for -prune. Examples from google don't seem to work in (my) FreeBSD.

chrisw at pcbsd% find .
.
./test.mov
./test.mpg
./dir1
./dir1/file1
./dir1/file2
./file3
chrisw at pcbsd% find . -print
.
./test.mov
./test.mpg
./dir1
./dir1/file1
./dir1/file2
./file3
chrisw at pcbsd% find . -print -o -prune dir1
find: dir1: unknown option
chrisw at pcbsd% find . -print -o -prune -name dir1
.
./test.mov
./test.mpg
./dir1
./dir1/file1
./dir1/file2
./file3
chrisw at pcbsd% find . -print -o -name dir1 -prune
.
./test.mov
./test.mpg
./dir1
./dir1/file1
./dir1/file2
./file3
chrisw at pcbsd% find . -o -name dir1 -prune
find: -o: no expression before -o
chrisw at pcbsd% find . -name "*" -o -name dir1 -prune
.
./test.mov
./test.mpg
./dir1
./dir1/file1
./dir1/file2
./file3
chrisw at pcbsd%

(Please don't tell me to read the man page, I have several times. Even 
Aeleen Frisch says it is impenetrable :P)

Chris


More information about the freebsd-questions mailing list