嘗試rsync文件的某些擴展名(*。sh),但下面的bash腳本仍然在傳輸所有文件,爲什麼?rsync --include選項不排除其他文件
from=/home/xxx rsync -zvr --include="*.sh" $from/* [email protected]$host:/home/tmp/
嘗試rsync文件的某些擴展名(*。sh),但下面的bash腳本仍然在傳輸所有文件,爲什麼?rsync --include選項不排除其他文件
from=/home/xxx rsync -zvr --include="*.sh" $from/* [email protected]$host:/home/tmp/
您需要添加一個 - 排除所有的,它有來後--include
rsync -zvr --include="*.sh" --exclude="*" $from/* [email protected]$host:/home/tmp/
--include
是哪些文件要沒有--exclude
。既然你在將來的論點中沒有排除任何論點,那就沒有效果。你可以這樣做:
from=/home/xxx
rsync -zvr --include="*.sh" --include="*/" --exclude="*" "$from" [email protected]$host:/home/tmp/
要遞歸複製所有文件.SH(額外--include
但千萬不要跳過可能包含.SH文件的目錄)
這是很好的做法,--include =「* /」是強制性的 – Labynocle
我認爲排除是在錯誤的地方;它應該在包含之後。 Rsync作用於第一個匹配模式。 – Hipponax43
Hipponax43是對的:你能糾正你的答案,因爲我和其他用戶一直在嘗試錯誤地回答你的問題 – Bob
在增加,至少在我的機器的事情(FreeBSD和OS X),這不起作用:
rsync -aP --include=*/ --include=*.txt --exclude=* * /path/to/dest
但確實:
rsync -aP --include=*/ --include=*.txt --exclude=* . /path/to/dest
ÿ es,通配當前目錄似乎覆蓋排除。
我通過--exclude固定改變--exclude = *問題= *。*,據我所知,*排除文件夾中包含文件。
關於遞歸的好處,@that。在OS X上,看起來排除(多個)必須遵循include(s)。我會認爲**找到。 -name'\ *。sh'| rsync -zvr --include-from = - --exclude ='*'... **可以工作,但它不會。 – JohnQ
正如注意到@that的答案是更好的,因爲你需要--include =「* /」來包含子目錄 –
我試過這個,它沒有傳輸任何數據。還嘗試使用包含語句之前和之後的排除,併產生相同的結果。 –