Skip to main content
added 470 characters in body
Source Link
Chris Davies
  • 128.2k
  • 16
  • 179
  • 324

You don't need the ** and for a single pattern you might as well just use --exclude. The --include pattern ensures that directories matching the --exclude pattern are included in the copy.

rsync -a  --exclude='*include '*/' --exclude='.*.swp' /home/username/Documents/ remotehost:/home/username/Documents/

If your remote username has /home/username as its home directory you can further simplify with a relative path:

rsync -a  --exclude='*include '*/' --exclude='.*.swp' /home/username/Documents/ remotehost:Documents/

Bear also in mind that vim will use other filenames for its swap file if one matching *.swp already exists or is in use. But you'll catch most of them with this single pattern. Here's what the documentation warns:

If this file already exists (e.g., when you are recovering from a crash) a warning is given and another extension is used, ".swo", ".swn", etc.

You could adapt the exclusion pattern to use .*.sw[a-p] if you were sufficiently concerned.

You don't need the ** and for a single pattern you might as well just use --exclude.

rsync -a --exclude='*.swp' /home/username/Documents/ remotehost:/home/username/Documents/

If your remote username has /home/username as its home directory you can further simplify with a relative path:

rsync -a --exclude='*.swp' /home/username/Documents/ remotehost:Documents/

You don't need the ** and for a single pattern you might as well just use --exclude. The --include pattern ensures that directories matching the --exclude pattern are included in the copy.

rsync -a  --include '*/' --exclude='.*.swp' /home/username/Documents/ remotehost:/home/username/Documents/

If your remote username has /home/username as its home directory you can further simplify with a relative path:

rsync -a  --include '*/' --exclude='.*.swp' /home/username/Documents/ remotehost:Documents/

Bear also in mind that vim will use other filenames for its swap file if one matching *.swp already exists or is in use. But you'll catch most of them with this single pattern. Here's what the documentation warns:

If this file already exists (e.g., when you are recovering from a crash) a warning is given and another extension is used, ".swo", ".swn", etc.

You could adapt the exclusion pattern to use .*.sw[a-p] if you were sufficiently concerned.

Source Link
Chris Davies
  • 128.2k
  • 16
  • 179
  • 324

You don't need the ** and for a single pattern you might as well just use --exclude.

rsync -a --exclude='*.swp' /home/username/Documents/ remotehost:/home/username/Documents/

If your remote username has /home/username as its home directory you can further simplify with a relative path:

rsync -a --exclude='*.swp' /home/username/Documents/ remotehost:Documents/