[英]how to transfer files that match a pattern with rsync
早上好,我想將目錄中的特定文件傳輸到遠程機器,同時保持子目錄的體系結構。 此外,我只想傳輸具有特殊擴展名的文件(例如“.txt”)。 我嘗試了以下方法:
rsync -aP --include *.txt ./sourceDirectory user@hostIP:destDirectory
但它會將所有文件復制到目標( destDirectory
),而不僅僅是那些與.txt
模式匹配的文件。 誰能幫我解出這樣的謎語?
PS:顯然,目錄sourceDirectory
包含我的.txt
文件所在的子目錄。
我曾經在將視頻同步到家庭 NAS 時遇到同樣的問題。 如果您閱讀 rsync 的手冊, --include
標志實際上意味着“不排除”。 它實際上必須與--exclude
標志一起使用。
以下命令將完成您的工作:
rsync -aP --include="*/" --include="*.txt" --exclude="*" sourceDirectory destDirectory
該命令的字面意思是排除所有內容,子文件夾和 txt 文件除外。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.