0

I know the exclude option in rsync can only accept relative paths, so I though I can make workaround with realpath --relative.

$ls /usr/local/bin
cppman  demangle  e  fusuma  rem  triangle
$realpath --relative-to=$PWD /usr/local/bin/cppman
../../usr/local/bin/cppman
$rsync -va --delete --exclude=$(realpath --relative-to=$PWD /usr/local/bin/cppman) /usr/local/bin /home/user1/Desktop/transport/
created directory /home/shepherd/Desktop/transport
bin/
bin/cppman
bin/demangle
bin/e
bin/fusuma
bin/rem
bin/triangle

sent 26,689 bytes  received 189 bytes  53,756.00 bytes/sec
total size is 26,215  speedup is 0.98

As you can see the file cppman is not excluded, despite being relative. Why?

0

The exclude path begins relative to your source ("root of the transfer"), not your current working dir. Since bin is the directory to be transferred, the path is /bin/cppman:

rsync -va --delete --exclude=/bin/cppman /usr/local/bin /home/user1/Desktop/transport/

Or unanchored (without the leading /):

rsync -va --delete --exclude=bin/cppman /usr/local/bin /home/user1/Desktop/transport/

If you had two files /usr/local/bin/cppman and /usr/local/bin/foo/bin/cppman, the unanchored version would exclude both files while the first command excludes the first file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.