6

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.

  • 2
    The answer is rsync...but you put that tag on your question yourself, so I guess you knew that?? – Wildcard Jan 2 '16 at 6:42
  • 1
    I'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? – cutrightjm Jan 2 '16 at 7:07
  • 1
    @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. – user Jan 2 '16 at 10:50
5

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.

  • rsync can also be done and ought to br done if in the Internet over ssh with -e ssh for security reasons – Rui F Ribeiro Jan 2 '16 at 9:43
  • The 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. – Rui F Ribeiro Jan 2 '16 at 10:39
  • @RuiFRibeiro ok. sorry (if any). I am deleting my redundant comment. – Pandya Jan 2 '16 at 10:44
  • @Pandya so --delete will delete files from the destination that are not in the source? – user Jan 2 '16 at 10:58
  • 1
    @user yes it will.., for more information run man rsync – Pandya Jan 2 '16 at 11:00
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  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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