2013-02-19 48 views
1

这是我的情况:[庆典]如何更新文件夹的内容

我有两个文件夹(A1和B1),我想包含在A1每个文件和子文件夹复制到B1与时间戳。我也想要,如果一个文件被修改,它必须被复制到B1与一个新的时间戳。

这样:

A1 contains: pluto.txt pippo(empty folder) 

B1 contains: pluto_timestamp.txt pippo(empty folder) 

后第2天:

A1 contains: pluto.txt pippo(empty folder) 

B1 contains: pluto_timestamp.txt pluto_timestamp2days.txt pippo(empty folder) 

我的想法是:

推出统计递归A1的命令并保存输出到一个txt文件。

像一个轮询器,当我的脚本被安排时,我想检查每个文件的修改字段,看看是否有一些文件已被修改。也许我可以做到这一点与其他推出统计命令

PSEUDOCODE 

while (A1 =! empty) { 

open stat_result.txt 

if file_A1 already exists in_B1 

     if modify_date_A1 =! modify_date_B1 

       cp file_A1_TIMESTAMP into B1 

     else do nothing 

else 

    cp file_A1_FILESTAMP into B1 #because it doesn't exist yet 

} 

希望能得到更清晰的。感谢

回答

0
rsync --archive --dry-run A1/ B1/ 

https://stackoverflow.com/tags/rsync/info

+0

我不Ghini这就是我需要的,因为也许我想操纵B1 namefile,例如 – rschirin 2013-02-20 00:09:22

+0

那么请编辑您的问题,以反映这一事实。 “必须将A1的文件(或子文件夹)版本相同的B1”没有提及它。但是你仍然可以在rsync之后操作B1中的文件。 – Perleone 2013-02-20 00:21:41

+0

我编辑了我的问题 – rschirin 2013-02-20 23:26:56

0
# first create the directories in B1, if they do not already exist 
# then copy the timestamped files to B1, if they are not there yet 
(cd A1; find -type d)|(cd B1; xargs mkdir -p) 
(cd A1; find -type f)| 
while read file 
do cp -n A1/$file B1/$(<<<$file sed "s,.*/[^.]*,&_`date -rA1/$file +%F_%T`,") 
done