[英]Update Files using Linux command line
I'm trying to create an update script that will merge the contents of two directories. 我正在尝试创建一个更新脚本,该脚本将合并两个目录的内容。 I have a master directory that has a structure like: 我有一个主目录,其结构如下:
master
- dir1
- subdir1
- subdir2
- dir2
- dir3
and an update directory like 和一个更新目录,例如
update
- dir1
-subdir2
How do I create a script that iterates through the update directory and replaces content in the master. 如何创建一个遍历更新目录并替换母版中内容的脚本。 I since the contents of the update directories contain different files than the master, it is imperative that I do not MERGE the files but replace the entire subdirectory. 由于更新目录的内容与主目录包含的文件不同,因此必须不要合并文件,而要替换整个子目录。
I've tried this 我已经试过了
for D in $(find -mindepth 3 -maxdepth 3 -type d) ;
do
rm -rf .$D
done
to remove the master directories but can't figure out how to manipulate the $D variable to copy the contents of the update to the master. 删除主目录,但无法弄清楚如何操作$ D变量将更新内容复制到主目录。 Perhaps this isn't the best way but couldn't find any other alternatives. 也许这不是最好的方法,但是找不到其他替代方法。
I finally did this: 我终于做到了:
for D in $(find -mindepth 3 -maxdepth 3 -type d) ;
do
rm -rf ../${D:2}
cp -avr ${D:2}/ ../${D:2}
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.