I am trying to backup files from cluster to my local computer. On the process, I am trying to avoid some unnecessary sub-directories from cluster being copied.

So I use rsync -av user@cluster.com:/home/dir . --exclude user@cluster.com:/home/dir/subdir, where subdir is the folder I am trying to avoid. However, the above option copies all files and folders including subdir. How to exclude subdir?

  • @Arronical: True. The exclude folder must be relative to the source directory and not the absolute path. – Sathish Sanjeevi Jul 27 '16 at 10:01
  • It works! I was putting it up as answer. But I would leave this for you.... – Sathish Sanjeevi Jul 27 '16 at 10:04
  • Yes. The solution is rsync -av user@cluster.com:/home/dir . --exclude subdir – Sathish Sanjeevi Jul 27 '16 at 10:11

The problem is that the path that you hand to --exclude should be relative to the original source path of the rsync command. This also means that you can do away with the / at the beginning of /subdir

Also there's no need to specify the user and host in the --exclude part.

So the correct command would be:

rsync -av user@cluster.com:/home/dir . --exclude subdir

Note that rsync --exclude can also do pattern matching, and the --exclude-from option is a great way to use a file listing multiple exclude patterns if you have more complicated exclusions.

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.