LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using the find command with a pipe to copy (https://www.linuxquestions.org/questions/linux-newbie-8/using-the-find-command-with-a-pipe-to-copy-562606/)

dbrmik 06-18-2007 03:51 AM

Using the find command with a pipe to copy
 
Hi

I want to be able to use the 'find' command to look for files containing a particular pattern (ignoring case) in their filenames ,then copy these to another directory.

I have not been able to get this to work. Is this possible?

Regards

Zmyrgel 06-18-2007 04:01 AM

Yes it should be something like this:
Code:

find / -name *baa* -exec "cp {} /home/baa/"

pwc101 06-18-2007 04:42 AM

Quote:

Originally Posted by Zmyrgel
Yes it should be something like this:
Code:

find / -name *baa* -exec "cp {} /home/baa/"

To ignore the case, you'd want -iname, not -name. You also need to enclose the *baa* in quotes, otherwise the shell parses it rather than letting find expand the asterisks. The find command needs to be finished with \; at the end too, and finally, the quotes need to go around the {}, not the whole cp command:
Code:

find / -iname "*baa*" -exec cp "{}" /home/baa/ \;
I think ;)

dbrmik 06-18-2007 05:08 AM

Thanks

pwc101 - works like a dream, thanks for the quick replies

very much appreciated


All times are GMT -5. The time now is 10:12 AM.