Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to copy all files of a type in a given directory and subdirectories but excluding files of a different type.

find /var/ftp/pub/bs -iname "*foo*.foo" -exec cp {} /var/ftp/pub/bs1 \;

which works but I'd rather do the exclude which is more accurate.

So I need to copy files with that end with *.foo but exclude files that contain foo1

Something like this (which doesn't work)

find /var/ftp/pub/bs -iname "*.foo" | grep --exclude="*foo1*" -exec cp {} /var/ftp/pub/bs1
share|improve this question
find ... -iname "*.foo" ! -iname "*foo1*" ...

You may need to escape the ! depending on your shell.

share|improve this answer
That worked. I did need to escape it. Thanks much! – user11064 Sep 27 '11 at 5:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.