How can I sync two local directories?
21,306
To sync the contents of dir1 to dir2 on the same system, type:
rsync -av --progress --delete dir1/ dir2
-a
,--archive
archive mode
--delete
delete extraneous files from dest dirs
-v
,--verbose
Verbose mode (increase verbosity)
--progress
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:
…/dir2/dir1/[files]
Related videos on Youtube
![Weylyn Savan](https://i.stack.imgur.com/3DNaY.jpg?s=256&g=1)
Author by
Weylyn Savan
Updated on September 18, 2022Comments
-
Weylyn Savan almost 2 years
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?
-
Kusalananda almost 7 yearsDo you want to do a one-way sync, or do you need to update the files both ways?
-
roaima almost 7 yearsYou seem to know one correct command (
rsync
). What have you tried so far?
-