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
find ... -iname "*.foo" ! -iname "*foo1*" ...

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

  • That worked. I did need to escape it. Thanks much! – user11064 Sep 27 '11 at 5:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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