是否有可能获得通配符匹配的值?也就是说我想做
scp -r user@host:some/path/with/*/file.txt cp/to/*/file.txt有了上面的命令,我想
some/path/with/TEST/file.txt --> cp/to/TEST/file.txt
some/path/with/OTHER/file.txt --> cp/to/OTHER/file.txt编辑:--我将添加更多关于实际设置的数据,这可能会使其更加清晰。
在我的服务器上我有一个结构
server $ pwd
~/sixtrack/simulations
server $ ls
run0001
run0002
run0003
...每个run*都是一个目录,包含run*/summary.dat、run*/tracks.dat等文件。我可以将所有内容复制到自己的计算机上,比如
pingul $ scp -r 'user@host:sixtrack/simulations/*' .然而,我不想复制每一个文件,而只是一些。因为所有文件的名称都是相同的,并且只能通过目录分隔,所以我必须尊重这个结构。因此,我希望host:sixtrack/simulations/run0001/summary.dat进入我的本地文件夹/Users/pingul/Workspace/simulations/run0001/summary.dat。
正在运行
pingul $ pwd
/Users/pingul/Workspace/simulations
pingul $ scp -r 'user@host:sixtrack/simulations/*/summary.dat' */.没有实现我想要的。按建议打印出添加-v选项
Executing: cp -r -- run0001/. run0100/.
Executing: cp -r -- run0002/. run0100/.
Executing: cp -r -- run0003/. run0100/.
...我只有一个summary.dat在run0100。所有其他目录都是空的(即run0001、run0002、.)
我想要的有可能吗?
发布于 2016-10-13 10:42:32
您所要求的是不可能的,因为cp/scp命令只需要一个目的地。但是,您可以很容易地用一些非常简单的脚本来模拟它:
for d in *
do
scp -r user@host:some/path/with/"$d"/file.txt cp/to/"$d"/file.txt
done它也可以写在一行上,如
for d in *; do scp -r user@host:some/path/with/"$d"/file.txt cp/to/"$d"/file.txt; donehttps://stackoverflow.com/questions/40015807
复制相似问题