2015-05-18 85 views
2

我想通過ssh將rsync文件從服務器傳輸到我的機器上。文件位於不同的子目錄中,但我只想保留與某種模式匹配的文件(IE blah .txt)。我已經做了大量的搜索和搜索stackoverflow,並且我已經嘗試了幾乎所有已經提出的--include和--excludes的排列。無論我嘗試什麼,rsync都會抓取所有文件。 正如我嘗試之一的例子,我用: rsync -avze 'ssh' --include='*blah*.txt' --exclude='*' [email protected]:/path/top/files/directory /path/to/local/directory通過ssh遞歸rsync,只包含一個文件擴展名

要解決問題,我想這個命令: rsync -avze 'ssh' --exclude='*' [email protected]:/path/top/files/directory /path/to/local/directory 希望它不會複製任何東西,但它仍然抓住了所有的文件。

我在OSX上使用rsync版本2.6.9。

有什麼明顯的我失蹤了嗎?我一直在努力爭取這一段時間。

+2

只是FYI,'rsync'有一個'--dry-run'標誌。 –

回答

0

OSX遵循BSD風格的rsync

https://www.freebsd.org/cgi/man.cgi?query=rsync&apropos=0&sektion=0&manpath=FreeBSD+8.0-RELEASE+and+Ports&format=html

-C,--cvs - 排除 這是排除大範圍的文件 的一個有用的速記,你常常不希望之間傳輸系統。它使用類似於CVS的 算法來確定是否忽略文件 。

 The exclude list is initialized to exclude the following items 
     (these initial items are marked as perishable -- see the FILTER 
     RULES section): 

     RCS SCCS CVS CVS.adm RCSLOG cvslog.* tags TAGS 
     .make.state .nse_depinfo *~ #* .#* ,* _$* *$ *.old *.bak 
     *.BAK *.orig *.rej .del-* *.a *.olb *.o *.obj *.so *.exe 
     *.Z *.elc *.ln core .svn/ .git/ .bzr/ 

     then, files listed in a $HOME/.cvsignore are added to the list 
     and any files listed in the CVSIGNORE environment variable (all 
     cvsignore names are delimited by whitespace). 

     Finally, any file is ignored if it is in the same directory as a 
     .cvsignore file and matches one of the patterns listed therein. 
     Unlike rsync's filter/exclude files, these patterns are split on 
     whitespace. See the cvs(1) manual for more information. 

     If you're combining -C with your own --filter rules, you should 
     note that these CVS excludes are appended at the end of your own 
     rules, regardless of where the -C was placed on the command- 
     line. This makes them a lower priority than any rules you spec- 
     ified explicitly. If you want to control where these CVS 
     excludes get inserted into your filter rules, you should omit 
     the -C as a command-line option and use a combination of --fil- 
     ter=:C and --filter=-C (either on your command-line or by 
     putting the ":C" and "-C" rules into a filter file with your 
     other rules). The first option turns on the per-directory scan- 
     ning for the .cvsignore file. The second option does a one-time 
     import of the CVS excludes mentioned above. 

    -f, --filter=RULE 
     This option allows you to add rules to selectively exclude cer- 
     tain files from the list of files to be transferred. This is 
     most useful in combination with a recursive transfer. 

     You may use as many --filter options on the command line as you 
     like to build up the list of files to exclude. If the filter 
     contains whitespace, be sure to quote it so that the shell gives 
     the rule to rsync as a single argument. The text below also 
     mentions that you can use an underscore to replace the space 
     that separates a rule from its arg. 

     See the FILTER RULES section for detailed information on this 
     option. 
2

我能找到一個解決方案,有一個警告。這裏是工作命令: rsync -vre 'ssh' --prune-empty-dirs --include='*/' --include='*blah*.txt' --exclude='*' [email protected]:/path/to/server/files /path/to/local/files

但是!如果我直接在我的命令行中輸入,它就會起作用。如果我將它保存到一個文件myfile.txt中,並且我嘗試`cat myfile.txt`,它就不再有效了!這對我來說沒有意義。

相關問題