複製多個檔案 - Linux

By Margaret
at 2013-08-24T05:01
at 2013-08-24T05:01
Table of Contents
※ 引述《zchien (小建)》之銘言:
: 請教..如果我有很多資料夾...分別要複製到不同目的地
: 因為檔案數量太多...因為我系統沒有rsync...如果不使用rsync
: 如果我只希望複製新增加的資料....我是否有機會使用find 指令..建立清單之後...
: 使用跑回圈的方式...依序丟到指定的不同資料夾.....
因為不是非常清楚你說的需求,所以,
我先假定你 "新增加資料" 的資料夾,與想要複製過去的 "不同" 目的地,
有一對一的對應關係...
建立一個路徑參考檔 path.lst,如下:
source1:destination1
source2:destination2
source3:destination3
以上檔案中,將所有來源目錄與目的目錄,分別用擔一行寫好,
其之間用 ":" 作分隔,要注意 ":" 前後沒有空白,
最後檔案尾端要有一行新行 (new line)。
然後作一個 script 檔名為 cpr:
#!/bin/bash
ReferenceFile=ReferenceFile.rf
if [ ! -e $ReferenceFile ]; then
touch $ReferenceFile
exit
fi
cat $1 |
while read line; do
SourcePath=`echo $line | cut --delimiter=":" --fields=1`
DestinationPath=`echo $line | cut --delimiter=":" --fields=2`
find $SourcePath -newer $ReferenceFile -exec cp -av {} $DestinationPath \;
done
touch $ReferenceFile
這個 script 的關鍵是:
他會檢查一個參考檔是否存在,也就是 "ReferenceFile.rf",不存在會自己建立。
這個 script 第一次執行時,會建立這個檔案,然後什麼也不做的離開,
但是這個檔案的建立日期時間,將被用來作為檢查你所謂 "新資料"。
~$ ./cpr
換句話說,自從第一次執行後,在你來源路徑中所累積的 "新資料",
將會被後面的 find 找到,然後更進一步被複製到你所指定的目的地去。
並且每次複製之後,會更新一次參考檔的檔案日期時間,
用來檢查下一次累積的 "新資料"。
所以爾後,你只要想進行複製最新資料:
~$ ./cpr path.lst
這樣看看是否符合你的需求,不行的話,再拿去按自己的喜好修改吧。
--
: 請教..如果我有很多資料夾...分別要複製到不同目的地
: 因為檔案數量太多...因為我系統沒有rsync...如果不使用rsync
: 如果我只希望複製新增加的資料....我是否有機會使用find 指令..建立清單之後...
: 使用跑回圈的方式...依序丟到指定的不同資料夾.....
因為不是非常清楚你說的需求,所以,
我先假定你 "新增加資料" 的資料夾,與想要複製過去的 "不同" 目的地,
有一對一的對應關係...
建立一個路徑參考檔 path.lst,如下:
source1:destination1
source2:destination2
source3:destination3
以上檔案中,將所有來源目錄與目的目錄,分別用擔一行寫好,
其之間用 ":" 作分隔,要注意 ":" 前後沒有空白,
最後檔案尾端要有一行新行 (new line)。
然後作一個 script 檔名為 cpr:
#!/bin/bash
ReferenceFile=ReferenceFile.rf
if [ ! -e $ReferenceFile ]; then
touch $ReferenceFile
exit
fi
cat $1 |
while read line; do
SourcePath=`echo $line | cut --delimiter=":" --fields=1`
DestinationPath=`echo $line | cut --delimiter=":" --fields=2`
find $SourcePath -newer $ReferenceFile -exec cp -av {} $DestinationPath \;
done
touch $ReferenceFile
這個 script 的關鍵是:
他會檢查一個參考檔是否存在,也就是 "ReferenceFile.rf",不存在會自己建立。
這個 script 第一次執行時,會建立這個檔案,然後什麼也不做的離開,
但是這個檔案的建立日期時間,將被用來作為檢查你所謂 "新資料"。
~$ ./cpr
換句話說,自從第一次執行後,在你來源路徑中所累積的 "新資料",
將會被後面的 find 找到,然後更進一步被複製到你所指定的目的地去。
並且每次複製之後,會更新一次參考檔的檔案日期時間,
用來檢查下一次累積的 "新資料"。
所以爾後,你只要想進行複製最新資料:
~$ ./cpr path.lst
這樣看看是否符合你的需求,不行的話,再拿去按自己的喜好修改吧。
--
Tags:
Linux
All Comments

By Susan
at 2013-08-28T20:51
at 2013-08-28T20:51

By Wallis
at 2013-09-02T11:17
at 2013-09-02T11:17

By Jacky
at 2013-09-05T15:27
at 2013-09-05T15:27

By Isabella
at 2013-09-08T09:06
at 2013-09-08T09:06

By Delia
at 2013-09-10T12:00
at 2013-09-10T12:00

By Jessica
at 2013-09-12T15:13
at 2013-09-12T15:13

By Edith
at 2013-09-12T22:22
at 2013-09-12T22:22

By Damian
at 2013-09-13T23:39
at 2013-09-13T23:39
Related Posts
LMDE 5.1聲道如何啟用?

By Joseph
at 2013-08-23T20:05
at 2013-08-23T20:05
ubuntu12.04無法進入圖形介面

By Adele
at 2013-08-23T19:48
at 2013-08-23T19:48
須在server前面裝防火牆嗎?

By Jacob
at 2013-08-23T17:09
at 2013-08-23T17:09
PD Ubuntu 時間無法更改

By Dinah
at 2013-08-23T15:29
at 2013-08-23T15:29
ubuntu12.04無法進入圖形介面

By Rae
at 2013-08-23T15:29
at 2013-08-23T15:29