我有这个目录结构:
% 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
当然有一种无需编写单独脚本即可执行此操作的方法吗?
这xargs
应该工作:
cd /tmp/dest_dir
\ls -d ??-?? | xargs -I{} cp /tmp/source_dir/{}/goodfile {}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句