【发布时间】:2016-04-29 12:31:12
【问题描述】:
我有这个目录结构:
% ls /tmp/source_dir/
aa-aa/ bb-bb/ cc-cc/ morejunk/ somejunk/
% ls /tmp/dest_dir
aa-aa/ bb-bb/ blah/ blahblah/
对于 dest_dir 中匹配 ??-?? 的每个目录,我想从 source_dir 复制相应的文件“goodfile”。我尝试了以下方法无济于事:
% cd /tmp/dest_dir
/tmp/dest_dir% \ls -d ??-?? | xargs cp /tmp/source_dir/{}/goodfile {}
cp: cannot stat `/tmp/source_dir/{}/goodfile': No such file or directory
cp: cannot stat `{}': No such file or directory
cp: omitting directory `aa-aa'
/tmp/dest_dir% \ls -d ??-?? | xargs bash -c "cp /tmp/source_dir/{$0}/goodfile {$0}"
cp: cannot stat `/tmp/source_dir/{/bin/bash}/goodfile': No such file or directory
肯定有办法在不编写单独脚本的情况下做到这一点吗?
【问题讨论】: