Sync File With Remote Using Rsync

A Linux command rsync example with explanation.

I build my static website locally with Hugo and use rsync to copy the files to my server. Here’s the command I use:

rsync -avz --delete -e 'ssh -p {server-port}' {local-directory}/ {username}@{server-ip}:{remote-directory}/
  • {username}: Your server’s username.
  • {server-ip}: The IP address of your server.
  • {local-directory}: The path to your site files on your machine.
  • {remote-directory}: The target path on your server.
  • The --delete flag ensures that files removed locally are also deleted on the server, keeping both directories in sync.