Search code examples
linuxbashrsync

rsync exclude pattern for `/index.php` but not for `/dir/subdir/index.php`


I am rsyncing files from localhost to host1 using the following command.

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

The problem with this command is it excludes index.php from any directory. But I want to exclude it only from root. That is I want ${SRC}/index.php should not be copied. But other will. How can I achieve this?


Solution

  • All rsync exclude paths use relative position to the source directory. So if you do --exclude="/index.php" it works how you want. But make sure ${SRC} has a trailing slash.