rsync exclude a directory but include a subdirectory

Sometime it’s just a detail.

Just change your include pattern adding a trailing / at the end of include pattern and it’ll work:

rsync -avz --delete --include=specs/install/project1/ \
    --exclude=specs/* /srv/http/projects/project/ \
    [email protected]:~/projects/project

Or, in alternative, prepare a filter file like this:

$ cat << EOF >pattern.txt
> + specs/install/project1/
> - specs/*
> EOF

Then use the –filter option:

rsync -avz --delete --filter=". pattern.txt" \
    /srv/http/projects/project/ \
    [email protected]:~/projects/project

For further info go to the FILTER RULES section in the rsync(1) manual page.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)