-   Linux - Newbie (
-   -   Recursive remote copy using wildcards (

jenser2 05-25-2009 05:12 AM

Recursive remote copy using wildcards
Hi guys,

I have a bunch of directories on a remote machine which look like they contain identical files and subdirectories but are the output of different model runs, so their content is different. The total output is quite large, so I want to copy certain files from certain subdirectories down to a local machine so I can compare the output from different runs. The directory structure has to be replicated, as the filenames are identical from each run.

Is there a one line command to do this or do I need to write a script? On the remote machine I have

/modeldir/expt1/subdir/file1 file2 file3
/modeldir/expt2/subdir/file1 file2 file3
/modeldir/expt3/subdir/file1 file2 file3

and would like to be able to do something like

scp -r user@remote:/modeldir/*/subdir/file[1-3] .

so that the directory structure is copied recursively. When I do this command, scp comes back with a 'no match' error message. When I do the following:

scp -r user@remote:/modeldir/expt1/subdir/file1 .

file1 gets copied to . without the subdirectories being recreated.

Any help appreciated!


colucix 05-25-2009 05:39 AM

You can try rsync in place of scp, so that the directory structure is created/preserved on the local machine:

rsync -e ssh -avz  user@remote:/modeldir .
If you want to copy just some files, use the proper include and exclude options. The following includes all the directories, includes all the files whose name: start with "file" and exclude the rest

rsync -e ssh -avz --include='*/' --include='file*' --exclude='*' user@remote:/modeldir .

All times are GMT -5. The time now is 11:21 PM.