This question already has an answer here:

I have two backup directories (dir1 and 2) on two different (local) HDDs and I want to create one of them. How can I really sync their contents so that both directories will have the same contents?

marked as duplicate by Stéphane Chazelas files Sep 15 '17 at 22:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Do you want to do a one-way sync, or do you need to update the files both ways? – Kusalananda Sep 15 '17 at 20:37
  • 1
    You seem to know one correct command (rsync). What have you tried so far? – roaima Sep 15 '17 at 20:57
  • @Kusalananda a one-way sync is enough for now because i want to delete dir1, but a two-way sync would be useful later. – Weylyn Savan Sep 16 '17 at 18:02
  • 1
    @roaima I only tried rsync -rtvu dir1 dir2/ as mentioned here without --delete. Now i see that the problem was the missing '/' from the end of 'dir1'. – Weylyn Savan Sep 16 '17 at 18:02

To sync the contents of dir1 to dir2 on the same system, type:

rsync -av --progress --delete dir1/ dir2

-a, --archive
        archive mode

        delete extraneous files from dest dirs

-v, --verbose
        Verbose mode (increase verbosity)

        show progress during transfer

                        — from rsync(1)

Note : The / after dir1 is necessary to mean "the contents of dir1".  Without the trailing slash, would place dir1, including the directory, within dir2. This would create a hierarchy that looks like:


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