How do I sync files between two drives?
Solution 1
You can use rsync
for that.
NAME
rsync - a fast, versatile, remote (and local) file-copying tool
Example:
rsync -av "/path/to/source" "/path/to/destination"
Note: Where "/path/to/source"
is the path of source directory and "/path/to/destination"
is the path to directory which contains destination directory. For example of you want to make synchronization between /media/users/disk1/dir
(as source) and /media/disk2/dir
(as destination), then you should run rsync -av "/media/users/disk1/dir" "/media/disk2/"
-
If you want to delete extraneous files from destination, you can use
--delete
option as follows:rsync -av --delete "/path/to/source" "/path/to/destination"
-
If you want to show the progress during transfer then use
--progress
as follows:rsync -avh --progress --delete "/path/to/source" "/path/to/destination"
There is also
--info=progress2
available for outputs statistics based on the whole transfer.
Note: For more information on rsync
visit (man rsync
) manpage and list of options. You can also use a GUI front-end.
Solution 2
You can also use Lsyncd.It will monitor continuously your mentioned directory tree and when changes happened it will automatically apply the changes.
It is actually similar to Rsync. You can use it for remote sync with SSH+Rsync. The hyperlink is its help page and it can give you more information.
Answer for your question:
lsyncd -rsync /path/directory1 /path/directory2
Related videos on Youtube
user
Updated on September 18, 2022Comments
-
user over 1 year
What command can check that a directory contains the same files as another directory, all the files are up to date and copy any updated files or new files to the first directory. It should not care about file permissions copying restricted files without checking back.
-
Wildcard over 8 yearsThe answer is
rsync
...but you put that tag on your question yourself, so I guess you knew that?? -
cutrightjm over 8 yearsI've noticed you have asked around 10 questions in the past day - how much effort are you actually putting in to trying to solve your own problems first?
-
user over 8 years@ekaj The majority of the time I know ether what I think the solutions or several solutions(I sort of gave it away with the rsync tag), but when working with sensitive data I like to check with other people to be safe. On this forum asking these types of questions seems to be the best way to verify, get better solutions or solve a problem I legitimately don't know how to fix.
-
-
Rui F Ribeiro over 8 yearsrsync can also be done and ought to br done if in the Internet over ssh with -e ssh for security reasons
-
Rui F Ribeiro over 8 yearsThe OP wont be the only one reading my comment. Security considerations should not ever be dismissed. please see my comment as an improvement and do not take it personaly.
-
Pandya over 8 years@RuiFRibeiro ok. sorry (if any). I am deleting my redundant comment.
-
user over 8 years@Pandya so --delete will delete files from the destination that are not in the source?
-
Pandya over 8 years@user yes it will.., for more information run
man rsync
-
user over 8 years@Pandya If I want it to copy everything even files set to root read only permissions should I use sudo. Are there any risks to using sudo/root.
-
Pandya over 8 years
-
Zelphir Kaltstahl over 6 yearsUnless I am misreading this answer, the paths are simply wrong. Say you want to copy a whole folder, you would need to have that folder in the source path as the last part and in the target path as the last part and not leaving it away in one place. Especially not with
--delete
. I almost deleted something following the path instruction in the answer, fortunately I had backup anyway.