How to sync two Linux directories?

Posted by nikola, With 0 Comments, Category: Linux, Tags: ,

You can sync two directories using command rsync.

Practical example is to run next command:

rsync -avz --delete /sourceDirectory /destinationDirectory

This will sync /destinationDirectory with content of /sourceDirectory, with additional:

  • a for archive more (more to follow about this),
  • v for verbose, and
  • z for zip compression.

Option --delete means that rsync delete option deletes files that are not there in source directory.

Archive more option does the following:

  • Recursive mode
  • Preserves symbolic links
  • Preserves permissions
  • Preserves timestamp
  • Preserves owner and group

This kind of syncing directories is useful for daily incremental backup.