Search code examples
linuxunixscriptingrsync

Cannot get rsync exclude option to exclude dir


Having an issues with rsync. I'm using rsync as a glorified cp command. I have in a script the following code.

rsync -aL --exclude /path/to/exclude/ --exclude='.*' /source/ /destination

I can get the rsync to exclude any hidden files. Hence the '.*' I cannot get the exclude dir to exclude. I've tried using an '=' sign, surrounding the dir with double quotes, with single quotes. Any help would be greatly appreciated. Thanks in advance.


Solution

  • mkdir -p test/a/b/c/d/e
    mkdir -p test/dest
    rsync -nvraL test/a test/dest --exclude=a/b/c/d 
    

    This works. As test/a is the base directory synced from, the exclude pattern is specified by starting with a/

    Show us the real paths/excludes if this doesn't help.

    Running rsync with -vn will list dirs/files - the pattern is matched against the format that rsync prints.