2013-02-19 49 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