Scripting help

Alejandro Pulver alejandro at varnet.biz
Thu May 12 10:30:27 PDT 2005


On Thu, 12 May 2005 11:44:49 -0500
Chris <racerx at makeworld.com> wrote:

> I would like some advice on how to script something that will search 
> directories below a named root for all files ending with a certain
> file extension.
> 
> Then, mv or cp them to another location.
> 
> 
> -- 
> Best regards,
> Chris

Hello,

Try this:

find /your/path -type f -name "*.tar" -exec cp {} /destination/dir \;

/your/path - put here the root path to operate on

-type f - type f means to search for "files"

-name "*.tar" - search for anything (*) ending in ".tar" (shell pattern)

-exec cp {} /destination/dir \; - execute the command "cp <file>
/destination/dir" replacing "<file>" with each file found (one at time).
The '\' is to escape the ';' (so it is not interpreted by the shell as a
command separator). 

It is also posible to do much more complex functions with 'find'. For
more information see "man find".

Hope that helps.

Best Regards,
Ale


More information about the freebsd-questions mailing list