How do I copy with scp with a wildcard(*) in the destination path? How do I copy with scp with a wildcard(*) in the destination path? shell shell

How do I copy with scp with a wildcard(*) in the destination path?


It depends on whether you want to expand * before running acommand or after running it and whether you want to do itinteractively or not.

If you want to expand it before running a command interactively you can either use insert-completions (M-*) or glob-expand-word (C-x *) described in man bash:

   glob-expand-word (C-x *)          The word before point is treated as a pattern for          pathname expansion, and the list of matching filenames          is inserted, replacing the word.  If a numeric argument          is sup- plied, an asterisk is appended before pathname          expansion.   insert-completions (M-*)          Insert all completions of the text before point that          would have been generated by possible-completions.

To use these functions put a cursor before or after * and press either Control-x * or Alt-*:

$ pwd/tmp/expand-glob$ lsFILE$ cp /tmp/expand-*/*

Now put your cursor after the last *, don't press Enterbut C-x * and you'll get this

$ cp /tmp/expand-glob/FILE

If you want to expand * to test command in the script then neitherscp nor cp is a good option because the cannot run in dry-runmode. You should go with something like rsync that would show whatfiles it would transfer if it was actually run like this:

$ rsync  -vn --relative /tmp/expand-*/* ./tmp//tmp/expand-scp//tmp/expand-scp/a/tmp/expand-scp/b/tmp/expand-scp/c/tmp/expand-scp/mmmm32

EDIT:

How about this:

$ rsync -avn -R --rsync-path="cd sixtrack/simulations && rsync"  user@host:run*/summary.dat .

-n stands for dry-run. With this option rsync will only print how will recreate a remote directory structure in current directory. In your case it will be something like:

receiving incremental file listdrwxr-xr-x          4,096 2016/10/13 12:45:36 run0001-rw-r--r--              0 2016/10/13 12:23:18 run0001/summary.datdrwxr-xr-x          4,096 2016/10/13 12:23:18 run00010-rw-r--r--              0 2016/10/13 12:23:18 run00010/summary.datdrwxr-xr-x          4,096 2016/10/13 12:23:18 run0002-rw-r--r--              0 2016/10/13 12:23:18 run0002/summary.datdrwxr-xr-x          4,096 2016/10/13 12:23:18 run0003-rw-r--r--              0 2016/10/13 12:23:18 run0003/summary.datdrwxr-xr-x          4,096 2016/10/13 12:23:18 run0004-rw-r--r--              0 2016/10/13 12:23:18 run0004/summary.datdrwxr-xr-x          4,096 2016/10/13 12:23:18 run0005-rw-r--r--              0 2016/10/13 12:23:18 run0005/summary.datdrwxr-xr-x          4,096 2016/10/13 12:23:18 run0006-rw-r--r--              0 2016/10/13 12:23:18 run0006/summary.datdrwxr-xr-x          4,096 2016/10/13 12:23:18 run0007-rw-r--r--              0 2016/10/13 12:23:18 run0007/summary.datdrwxr-xr-x          4,096 2016/10/13 12:23:18 run0008-rw-r--r--              0 2016/10/13 12:23:18 run0008/summary.datdrwxr-xr-x          4,096 2016/10/13 12:23:18 run0009-rw-r--r--              0 2016/10/13 12:23:18 run0009/summary.dat


What you're asking for is impossible since cp/scp commands take only a single destination. However you can easily simulate it with some very straightforward scripting:

for d in *do    scp -r user@host:some/path/with/"$d"/file.txt cp/to/"$d"/file.txtdone

It can also be written on a single line as

for d in *; do scp -r user@host:some/path/with/"$d"/file.txt cp/to/"$d"/file.txt; done