假设我有:
dir_1
- file_a
- subdir_0
- file_b
- file_c
dir_2
- file_a
- subdir_0
- file_b
我想将两个目录中存在的每个文件复制到 dir_2。在上面的例子中,这意味着file_a
and subdir_0/file_b
.
在 bash 中实现此目的最简单的方法是什么?
One find/while/read
idea:
while read -r tgt
do
src="${tgt//dir_2/dir_1}"
[[ -f "${src}" ]] && echo cp "${src}" "${tgt}" # if satisfied with output then remove the 'echo'
done < <(find dir_2 -type f)
这会生成:
cp dir_1/file_a dir_2/file_a
cp dir_1/subdir_0/file_b dir_2/subdir_0/file_b
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)