2012-03-07 48 views
2

我使用以下命令將文件從localhost更改爲host1rsync排除`/ index.php`的模式,但不適用於`/ dir/subdir/index.php`

rsync  -vq -ar \ 
      --exclude="index.php" \ 
      --exclude="var*" \ 
      --exclude=".svn*" \ 
      --exclude="*~" \ 
      --exclude="Doxyfile" \ 
      --exclude="*.kdev*" 
      --exclude="nbproject" \ 
      ${SRC} [email protected]${HOST}:${RLOC} && echo Files synchronised. 

該命令的問題是它從任何目錄中排除index.php。但我想只從根目錄中排除它。那就是我想${SRC}/index.php不應該被複制。但其他意願。我怎樣才能做到這一點?

+0

你試過'--exclude =/index.php'還是'--exclude =「$ SRC/index.php」'? – 2012-03-07 22:09:33

+0

@NiklasB我多麼盲目!第二種模式更有意義。 – 2012-03-07 22:13:50

回答

4

所有rsync排除路徑使用相對位置到源目錄。所以如果你這樣做--exclude =「/ index.php」它的工作方式你想要的。但請確保$ {SRC}具有尾部斜線。

+0

爲什麼在'$ {SRC}'後放置'/'? – 2012-03-07 22:14:25

+1

因爲否則它不會檢測相對於源路徑的/index.php。不知道爲什麼rsync是這樣做的,但我發現是這樣 – 2012-03-07 22:28:23