在终端中,将多个文件夹合并成一个 [英] In terminal, merging multiple folders into one
问题描述
我有一个由WDBackup(西部数字外部高清备份工具)创建的备份目录,它包含备份的每一天的目录,以及备份的增量内容。
I have a backup directory created by WDBackup (western digital external HD backup util) that contains a directory for each day that it backed up and the incremental contents of just what was backed up.
所以层次结构如下:
20100101
My Documents
Letter1.doc
My Music
Best Songs Every
First Songs.mp3
My song.mp3 # modified 20100101
20100102
My Documents
Important Docs
Taxes.doc
My Music
My Song.mp3 # modified 20100102
...etc...
只有已更改的内容已备份,并且第一次备份包含所有选择进行备份的文件。
Only what has changed is backed up and the first backup that was ever made contains all the files selected for backup.
我现在想做的是增量复制,同时保持文件夹结构,从最旧到最新,每个这些日期的文件夹到一个'合并'文件夹,它覆盖旧的内容并保留新的东西。
What I'm trying to do now is incrementally copy, while keeping the folder structure, from oldest to newest, each of these dated folders into a 'merged' folder so that it overrides the older content and keeps the new stuff.
例如,如果只使用这两个示例文件夹,最终合并的文件夹将如下所示:
As an example, if just using these two example folders, the final merged folder would look like this:
Merged
My Documents
Important Docs
Taxes.doc
Letter1.doc
My Music
Best Songs Every
First Songs.mp3
My Song.mp3 # modified 20100102
希望说得通。
感谢,
Josh
推荐答案
您可以在bash for循环中使用rsync,例如:
You can use rsync in a bash for loop, e.g.:
$ for d in 2010* ; do rsync -av ./$d/ ./Merged/ ; done
请注意,在运行之前你可能只是想谨慎,你可以使用rsync的 -n
标志做一个干运行:
Note that before running this for real you might just want to be cautious and test that it's actually going to do what you want it to - for this you can use rsync's -n
flag to do a "dry run":
$ for d in 2010* ; do rsync -avn ./$d/ ./Merged/ ; done
这篇关于在终端中,将多个文件夹合并成一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!