How to sync two folders with command line tools?












38















Having migrated to Linux from Windows, I would like to find an alternative software to Winmerge or rather learn command line tools to compare and sync two folders on Linux. I would be grateful if you could tell me how to do the following tasks on the command line... (I have studied diff and rsync, but I still need some help.)



We have two folders: "/home/user/A" and "/home/user/B"



Folder A is the place where regular files and folders are saved and folder B is a backup folder that serves as a complete mirror of folder A. (Nothing is directly saved or modified by the user in folder B.)



My questions are:




  • How to list files that exist only in folder B? (E.g. the ones deleted from folder A since the last synchronization.)


  • How to copy files that exist in only folder B back into folder A?


  • How to list files that exist in both folders but have different timestamps or sizes? (The ones that have been modified in folder A since last synronization. I would like to avoid using checksums, because there are tens of thousands of files and it'd make the process too slow.)


  • How to make an exact copy of folder A into folder B? I mean, copy everything from folder A into folder B that exists only in folder A and delete everything from folder B that exists only in folder B, but without touching the files that are the same in both folders.











share|improve this question

























  • Why not use a proper backup program for this? Duplicity is one example.

    – Qudit
    May 16 '15 at 21:57
















38















Having migrated to Linux from Windows, I would like to find an alternative software to Winmerge or rather learn command line tools to compare and sync two folders on Linux. I would be grateful if you could tell me how to do the following tasks on the command line... (I have studied diff and rsync, but I still need some help.)



We have two folders: "/home/user/A" and "/home/user/B"



Folder A is the place where regular files and folders are saved and folder B is a backup folder that serves as a complete mirror of folder A. (Nothing is directly saved or modified by the user in folder B.)



My questions are:




  • How to list files that exist only in folder B? (E.g. the ones deleted from folder A since the last synchronization.)


  • How to copy files that exist in only folder B back into folder A?


  • How to list files that exist in both folders but have different timestamps or sizes? (The ones that have been modified in folder A since last synronization. I would like to avoid using checksums, because there are tens of thousands of files and it'd make the process too slow.)


  • How to make an exact copy of folder A into folder B? I mean, copy everything from folder A into folder B that exists only in folder A and delete everything from folder B that exists only in folder B, but without touching the files that are the same in both folders.











share|improve this question

























  • Why not use a proper backup program for this? Duplicity is one example.

    – Qudit
    May 16 '15 at 21:57














38












38








38


16






Having migrated to Linux from Windows, I would like to find an alternative software to Winmerge or rather learn command line tools to compare and sync two folders on Linux. I would be grateful if you could tell me how to do the following tasks on the command line... (I have studied diff and rsync, but I still need some help.)



We have two folders: "/home/user/A" and "/home/user/B"



Folder A is the place where regular files and folders are saved and folder B is a backup folder that serves as a complete mirror of folder A. (Nothing is directly saved or modified by the user in folder B.)



My questions are:




  • How to list files that exist only in folder B? (E.g. the ones deleted from folder A since the last synchronization.)


  • How to copy files that exist in only folder B back into folder A?


  • How to list files that exist in both folders but have different timestamps or sizes? (The ones that have been modified in folder A since last synronization. I would like to avoid using checksums, because there are tens of thousands of files and it'd make the process too slow.)


  • How to make an exact copy of folder A into folder B? I mean, copy everything from folder A into folder B that exists only in folder A and delete everything from folder B that exists only in folder B, but without touching the files that are the same in both folders.











share|improve this question
















Having migrated to Linux from Windows, I would like to find an alternative software to Winmerge or rather learn command line tools to compare and sync two folders on Linux. I would be grateful if you could tell me how to do the following tasks on the command line... (I have studied diff and rsync, but I still need some help.)



We have two folders: "/home/user/A" and "/home/user/B"



Folder A is the place where regular files and folders are saved and folder B is a backup folder that serves as a complete mirror of folder A. (Nothing is directly saved or modified by the user in folder B.)



My questions are:




  • How to list files that exist only in folder B? (E.g. the ones deleted from folder A since the last synchronization.)


  • How to copy files that exist in only folder B back into folder A?


  • How to list files that exist in both folders but have different timestamps or sizes? (The ones that have been modified in folder A since last synronization. I would like to avoid using checksums, because there are tens of thousands of files and it'd make the process too slow.)


  • How to make an exact copy of folder A into folder B? I mean, copy everything from folder A into folder B that exists only in folder A and delete everything from folder B that exists only in folder B, but without touching the files that are the same in both folders.








files file-copy synchronization






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 26 '17 at 22:54









MikeyE

1035




1035










asked May 16 '15 at 20:49









akopacsiakopacsi

293136




293136













  • Why not use a proper backup program for this? Duplicity is one example.

    – Qudit
    May 16 '15 at 21:57



















  • Why not use a proper backup program for this? Duplicity is one example.

    – Qudit
    May 16 '15 at 21:57

















Why not use a proper backup program for this? Duplicity is one example.

– Qudit
May 16 '15 at 21:57





Why not use a proper backup program for this? Duplicity is one example.

– Qudit
May 16 '15 at 21:57










4 Answers
4






active

oldest

votes


















57














This puts folder A into folder B:



rsync -avu --delete "/home/user/A" "/home/user/B"  


If you want the contents of folders A and B to be the same, put /home/user/A/ (with the slash) as the source. This takes not the folder A but all of it's content and puts it into folder B. Like this:



rsync -avu --delete "/home/user/A/" "/home/user/B"  


Explanation by SonicARG



-a Do the sync preserving all filesystem attributes



-v run verbosely



-u skip files that are newer on the receiver



--delete delete the files in target folder that do not exist in the source, /home/user/A: source folder, /home/user/B: target folder






share|improve this answer





















  • 6





    rsync: run rsync app, -a: do the sync preserving all filesystem attributes, -v: run verbosely, -z: compress the data during the sync (transport the data in compressed mode), --delete: delete the files in target folder that do not exist in the source, /home/user/A: source folder, /home/user/B: target folder

    – SonicARG
    Jul 9 '16 at 19:25











  • Hi SonicARG, I totally forgot to get back to this and put the explanation, thanks submitting the explanation, I put yours in the answer, hope you don't mind.

    – TuxForLife
    Jul 11 '16 at 5:43








  • 5





    Rsync is primarly meant to copy files between different computers, as explained here it can serve the purpose to sync directories as well. So the -z option is interesting to reduce network traffic and thus enhance the performance of an rsync between 2 computers: ( read data from disk -> compress) ===network===> (uncompress->write to disk) Using -z to sync 2 directories on the same host is a bit silly and waste of cpu cycles as you would get (read data from disk -> compress -> uncompress -> write to disk)

    – GerritCap
    Mar 29 '17 at 8:51













  • @GerritCap, I made an edit, thanks for your valuable input

    – TuxForLife
    Jul 6 '18 at 15:48











  • I've tried the command but it create a sub-dir /home/user/B/A instead of overwrite A's content to B's content. Could you help me to have a look on it?

    – Luke
    Sep 19 '18 at 3:24





















4














You could unison tool developed by Benjamin Pierce at U Penn.



Let us assume you have two directories,



/home/user/Documents/dirA/ and /home/user/Documents/dirB/



To synchronize these two, you may use:



~$unison -ui text /home/user/Documents/dirA/ /home/user/Documents/dirB/



In output, unison will display each and every directory and file that is different in the two directories you have asked to sync. It will recommend to additively synchronize (replicate missing file in both locations) on the initial run, then create and maintain a synchronization tree on your machine, and on subsequent runs it will implement true synchronization (i.e., if you delete a file from .../dirA, it will get deleted from .../dirB as well. You can also compare each and every change and optionally choose to forward or reverse synchronize between the two directories.



Optionally, to launch graphical interface, simply remove the -ui text option from your command, although I find the cli simpler and faster to use.



More on this: Unison tutorial at Unison user documentation.






share|improve this answer































    0














    This is not completely the same as what you ask for, but you could considered using a version-control tool. Tools like Git do everything you ask for, and more, especially if you do not work in folder B directly it could be interesting to take a look at it. you can find some more information on git here






    share|improve this answer





















    • 2





      This only works if you're willing to add everything to version control. It also forces every change ever committed to be permanently stored, which may be undesirable.

      – Qudit
      May 16 '15 at 21:58











    • @Qudit, that is true, although it is possible via cloning to limit the history, but limiting the history is not (yet ?) implemented in Git by default.

      – switch87
      May 16 '15 at 22:07











    • @switch87 Yes, I know you can delete old commits. Version control is not really an appropriate solution for generic backups imo though, especially if there are large binary files.

      – Qudit
      May 16 '15 at 22:10











    • His question is for local backup, but if you use it for remote backup you can still use git annex for the bigger files. for local backup this is not a problem.

      – switch87
      May 16 '15 at 22:22






    • 2





      @switch87 This really should've been a comment to the Q and not an answer since it doesn't explain how you'd use git to do backups.

      – slm
      May 17 '15 at 11:35



















    0














    You can use it this way:



    rsync -avu --delete /home/user/A/* /home/user/B/


    This way you will copy the content of folder A into folder B, not the content of folder A itself.






    share|improve this answer

























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "106"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f203846%2fhow-to-sync-two-folders-with-command-line-tools%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      57














      This puts folder A into folder B:



      rsync -avu --delete "/home/user/A" "/home/user/B"  


      If you want the contents of folders A and B to be the same, put /home/user/A/ (with the slash) as the source. This takes not the folder A but all of it's content and puts it into folder B. Like this:



      rsync -avu --delete "/home/user/A/" "/home/user/B"  


      Explanation by SonicARG



      -a Do the sync preserving all filesystem attributes



      -v run verbosely



      -u skip files that are newer on the receiver



      --delete delete the files in target folder that do not exist in the source, /home/user/A: source folder, /home/user/B: target folder






      share|improve this answer





















      • 6





        rsync: run rsync app, -a: do the sync preserving all filesystem attributes, -v: run verbosely, -z: compress the data during the sync (transport the data in compressed mode), --delete: delete the files in target folder that do not exist in the source, /home/user/A: source folder, /home/user/B: target folder

        – SonicARG
        Jul 9 '16 at 19:25











      • Hi SonicARG, I totally forgot to get back to this and put the explanation, thanks submitting the explanation, I put yours in the answer, hope you don't mind.

        – TuxForLife
        Jul 11 '16 at 5:43








      • 5





        Rsync is primarly meant to copy files between different computers, as explained here it can serve the purpose to sync directories as well. So the -z option is interesting to reduce network traffic and thus enhance the performance of an rsync between 2 computers: ( read data from disk -> compress) ===network===> (uncompress->write to disk) Using -z to sync 2 directories on the same host is a bit silly and waste of cpu cycles as you would get (read data from disk -> compress -> uncompress -> write to disk)

        – GerritCap
        Mar 29 '17 at 8:51













      • @GerritCap, I made an edit, thanks for your valuable input

        – TuxForLife
        Jul 6 '18 at 15:48











      • I've tried the command but it create a sub-dir /home/user/B/A instead of overwrite A's content to B's content. Could you help me to have a look on it?

        – Luke
        Sep 19 '18 at 3:24


















      57














      This puts folder A into folder B:



      rsync -avu --delete "/home/user/A" "/home/user/B"  


      If you want the contents of folders A and B to be the same, put /home/user/A/ (with the slash) as the source. This takes not the folder A but all of it's content and puts it into folder B. Like this:



      rsync -avu --delete "/home/user/A/" "/home/user/B"  


      Explanation by SonicARG



      -a Do the sync preserving all filesystem attributes



      -v run verbosely



      -u skip files that are newer on the receiver



      --delete delete the files in target folder that do not exist in the source, /home/user/A: source folder, /home/user/B: target folder






      share|improve this answer





















      • 6





        rsync: run rsync app, -a: do the sync preserving all filesystem attributes, -v: run verbosely, -z: compress the data during the sync (transport the data in compressed mode), --delete: delete the files in target folder that do not exist in the source, /home/user/A: source folder, /home/user/B: target folder

        – SonicARG
        Jul 9 '16 at 19:25











      • Hi SonicARG, I totally forgot to get back to this and put the explanation, thanks submitting the explanation, I put yours in the answer, hope you don't mind.

        – TuxForLife
        Jul 11 '16 at 5:43








      • 5





        Rsync is primarly meant to copy files between different computers, as explained here it can serve the purpose to sync directories as well. So the -z option is interesting to reduce network traffic and thus enhance the performance of an rsync between 2 computers: ( read data from disk -> compress) ===network===> (uncompress->write to disk) Using -z to sync 2 directories on the same host is a bit silly and waste of cpu cycles as you would get (read data from disk -> compress -> uncompress -> write to disk)

        – GerritCap
        Mar 29 '17 at 8:51













      • @GerritCap, I made an edit, thanks for your valuable input

        – TuxForLife
        Jul 6 '18 at 15:48











      • I've tried the command but it create a sub-dir /home/user/B/A instead of overwrite A's content to B's content. Could you help me to have a look on it?

        – Luke
        Sep 19 '18 at 3:24
















      57












      57








      57







      This puts folder A into folder B:



      rsync -avu --delete "/home/user/A" "/home/user/B"  


      If you want the contents of folders A and B to be the same, put /home/user/A/ (with the slash) as the source. This takes not the folder A but all of it's content and puts it into folder B. Like this:



      rsync -avu --delete "/home/user/A/" "/home/user/B"  


      Explanation by SonicARG



      -a Do the sync preserving all filesystem attributes



      -v run verbosely



      -u skip files that are newer on the receiver



      --delete delete the files in target folder that do not exist in the source, /home/user/A: source folder, /home/user/B: target folder






      share|improve this answer















      This puts folder A into folder B:



      rsync -avu --delete "/home/user/A" "/home/user/B"  


      If you want the contents of folders A and B to be the same, put /home/user/A/ (with the slash) as the source. This takes not the folder A but all of it's content and puts it into folder B. Like this:



      rsync -avu --delete "/home/user/A/" "/home/user/B"  


      Explanation by SonicARG



      -a Do the sync preserving all filesystem attributes



      -v run verbosely



      -u skip files that are newer on the receiver



      --delete delete the files in target folder that do not exist in the source, /home/user/A: source folder, /home/user/B: target folder







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jan 11 at 11:10









      andialles

      32




      32










      answered May 16 '15 at 22:04









      TuxForLifeTuxForLife

      767616




      767616








      • 6





        rsync: run rsync app, -a: do the sync preserving all filesystem attributes, -v: run verbosely, -z: compress the data during the sync (transport the data in compressed mode), --delete: delete the files in target folder that do not exist in the source, /home/user/A: source folder, /home/user/B: target folder

        – SonicARG
        Jul 9 '16 at 19:25











      • Hi SonicARG, I totally forgot to get back to this and put the explanation, thanks submitting the explanation, I put yours in the answer, hope you don't mind.

        – TuxForLife
        Jul 11 '16 at 5:43








      • 5





        Rsync is primarly meant to copy files between different computers, as explained here it can serve the purpose to sync directories as well. So the -z option is interesting to reduce network traffic and thus enhance the performance of an rsync between 2 computers: ( read data from disk -> compress) ===network===> (uncompress->write to disk) Using -z to sync 2 directories on the same host is a bit silly and waste of cpu cycles as you would get (read data from disk -> compress -> uncompress -> write to disk)

        – GerritCap
        Mar 29 '17 at 8:51













      • @GerritCap, I made an edit, thanks for your valuable input

        – TuxForLife
        Jul 6 '18 at 15:48











      • I've tried the command but it create a sub-dir /home/user/B/A instead of overwrite A's content to B's content. Could you help me to have a look on it?

        – Luke
        Sep 19 '18 at 3:24
















      • 6





        rsync: run rsync app, -a: do the sync preserving all filesystem attributes, -v: run verbosely, -z: compress the data during the sync (transport the data in compressed mode), --delete: delete the files in target folder that do not exist in the source, /home/user/A: source folder, /home/user/B: target folder

        – SonicARG
        Jul 9 '16 at 19:25











      • Hi SonicARG, I totally forgot to get back to this and put the explanation, thanks submitting the explanation, I put yours in the answer, hope you don't mind.

        – TuxForLife
        Jul 11 '16 at 5:43








      • 5





        Rsync is primarly meant to copy files between different computers, as explained here it can serve the purpose to sync directories as well. So the -z option is interesting to reduce network traffic and thus enhance the performance of an rsync between 2 computers: ( read data from disk -> compress) ===network===> (uncompress->write to disk) Using -z to sync 2 directories on the same host is a bit silly and waste of cpu cycles as you would get (read data from disk -> compress -> uncompress -> write to disk)

        – GerritCap
        Mar 29 '17 at 8:51













      • @GerritCap, I made an edit, thanks for your valuable input

        – TuxForLife
        Jul 6 '18 at 15:48











      • I've tried the command but it create a sub-dir /home/user/B/A instead of overwrite A's content to B's content. Could you help me to have a look on it?

        – Luke
        Sep 19 '18 at 3:24










      6




      6





      rsync: run rsync app, -a: do the sync preserving all filesystem attributes, -v: run verbosely, -z: compress the data during the sync (transport the data in compressed mode), --delete: delete the files in target folder that do not exist in the source, /home/user/A: source folder, /home/user/B: target folder

      – SonicARG
      Jul 9 '16 at 19:25





      rsync: run rsync app, -a: do the sync preserving all filesystem attributes, -v: run verbosely, -z: compress the data during the sync (transport the data in compressed mode), --delete: delete the files in target folder that do not exist in the source, /home/user/A: source folder, /home/user/B: target folder

      – SonicARG
      Jul 9 '16 at 19:25













      Hi SonicARG, I totally forgot to get back to this and put the explanation, thanks submitting the explanation, I put yours in the answer, hope you don't mind.

      – TuxForLife
      Jul 11 '16 at 5:43







      Hi SonicARG, I totally forgot to get back to this and put the explanation, thanks submitting the explanation, I put yours in the answer, hope you don't mind.

      – TuxForLife
      Jul 11 '16 at 5:43






      5




      5





      Rsync is primarly meant to copy files between different computers, as explained here it can serve the purpose to sync directories as well. So the -z option is interesting to reduce network traffic and thus enhance the performance of an rsync between 2 computers: ( read data from disk -> compress) ===network===> (uncompress->write to disk) Using -z to sync 2 directories on the same host is a bit silly and waste of cpu cycles as you would get (read data from disk -> compress -> uncompress -> write to disk)

      – GerritCap
      Mar 29 '17 at 8:51







      Rsync is primarly meant to copy files between different computers, as explained here it can serve the purpose to sync directories as well. So the -z option is interesting to reduce network traffic and thus enhance the performance of an rsync between 2 computers: ( read data from disk -> compress) ===network===> (uncompress->write to disk) Using -z to sync 2 directories on the same host is a bit silly and waste of cpu cycles as you would get (read data from disk -> compress -> uncompress -> write to disk)

      – GerritCap
      Mar 29 '17 at 8:51















      @GerritCap, I made an edit, thanks for your valuable input

      – TuxForLife
      Jul 6 '18 at 15:48





      @GerritCap, I made an edit, thanks for your valuable input

      – TuxForLife
      Jul 6 '18 at 15:48













      I've tried the command but it create a sub-dir /home/user/B/A instead of overwrite A's content to B's content. Could you help me to have a look on it?

      – Luke
      Sep 19 '18 at 3:24







      I've tried the command but it create a sub-dir /home/user/B/A instead of overwrite A's content to B's content. Could you help me to have a look on it?

      – Luke
      Sep 19 '18 at 3:24















      4














      You could unison tool developed by Benjamin Pierce at U Penn.



      Let us assume you have two directories,



      /home/user/Documents/dirA/ and /home/user/Documents/dirB/



      To synchronize these two, you may use:



      ~$unison -ui text /home/user/Documents/dirA/ /home/user/Documents/dirB/



      In output, unison will display each and every directory and file that is different in the two directories you have asked to sync. It will recommend to additively synchronize (replicate missing file in both locations) on the initial run, then create and maintain a synchronization tree on your machine, and on subsequent runs it will implement true synchronization (i.e., if you delete a file from .../dirA, it will get deleted from .../dirB as well. You can also compare each and every change and optionally choose to forward or reverse synchronize between the two directories.



      Optionally, to launch graphical interface, simply remove the -ui text option from your command, although I find the cli simpler and faster to use.



      More on this: Unison tutorial at Unison user documentation.






      share|improve this answer




























        4














        You could unison tool developed by Benjamin Pierce at U Penn.



        Let us assume you have two directories,



        /home/user/Documents/dirA/ and /home/user/Documents/dirB/



        To synchronize these two, you may use:



        ~$unison -ui text /home/user/Documents/dirA/ /home/user/Documents/dirB/



        In output, unison will display each and every directory and file that is different in the two directories you have asked to sync. It will recommend to additively synchronize (replicate missing file in both locations) on the initial run, then create and maintain a synchronization tree on your machine, and on subsequent runs it will implement true synchronization (i.e., if you delete a file from .../dirA, it will get deleted from .../dirB as well. You can also compare each and every change and optionally choose to forward or reverse synchronize between the two directories.



        Optionally, to launch graphical interface, simply remove the -ui text option from your command, although I find the cli simpler and faster to use.



        More on this: Unison tutorial at Unison user documentation.






        share|improve this answer


























          4












          4








          4







          You could unison tool developed by Benjamin Pierce at U Penn.



          Let us assume you have two directories,



          /home/user/Documents/dirA/ and /home/user/Documents/dirB/



          To synchronize these two, you may use:



          ~$unison -ui text /home/user/Documents/dirA/ /home/user/Documents/dirB/



          In output, unison will display each and every directory and file that is different in the two directories you have asked to sync. It will recommend to additively synchronize (replicate missing file in both locations) on the initial run, then create and maintain a synchronization tree on your machine, and on subsequent runs it will implement true synchronization (i.e., if you delete a file from .../dirA, it will get deleted from .../dirB as well. You can also compare each and every change and optionally choose to forward or reverse synchronize between the two directories.



          Optionally, to launch graphical interface, simply remove the -ui text option from your command, although I find the cli simpler and faster to use.



          More on this: Unison tutorial at Unison user documentation.






          share|improve this answer













          You could unison tool developed by Benjamin Pierce at U Penn.



          Let us assume you have two directories,



          /home/user/Documents/dirA/ and /home/user/Documents/dirB/



          To synchronize these two, you may use:



          ~$unison -ui text /home/user/Documents/dirA/ /home/user/Documents/dirB/



          In output, unison will display each and every directory and file that is different in the two directories you have asked to sync. It will recommend to additively synchronize (replicate missing file in both locations) on the initial run, then create and maintain a synchronization tree on your machine, and on subsequent runs it will implement true synchronization (i.e., if you delete a file from .../dirA, it will get deleted from .../dirB as well. You can also compare each and every change and optionally choose to forward or reverse synchronize between the two directories.



          Optionally, to launch graphical interface, simply remove the -ui text option from your command, although I find the cli simpler and faster to use.



          More on this: Unison tutorial at Unison user documentation.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 2 '17 at 8:21









          AalokAalok

          15710




          15710























              0














              This is not completely the same as what you ask for, but you could considered using a version-control tool. Tools like Git do everything you ask for, and more, especially if you do not work in folder B directly it could be interesting to take a look at it. you can find some more information on git here






              share|improve this answer





















              • 2





                This only works if you're willing to add everything to version control. It also forces every change ever committed to be permanently stored, which may be undesirable.

                – Qudit
                May 16 '15 at 21:58











              • @Qudit, that is true, although it is possible via cloning to limit the history, but limiting the history is not (yet ?) implemented in Git by default.

                – switch87
                May 16 '15 at 22:07











              • @switch87 Yes, I know you can delete old commits. Version control is not really an appropriate solution for generic backups imo though, especially if there are large binary files.

                – Qudit
                May 16 '15 at 22:10











              • His question is for local backup, but if you use it for remote backup you can still use git annex for the bigger files. for local backup this is not a problem.

                – switch87
                May 16 '15 at 22:22






              • 2





                @switch87 This really should've been a comment to the Q and not an answer since it doesn't explain how you'd use git to do backups.

                – slm
                May 17 '15 at 11:35
















              0














              This is not completely the same as what you ask for, but you could considered using a version-control tool. Tools like Git do everything you ask for, and more, especially if you do not work in folder B directly it could be interesting to take a look at it. you can find some more information on git here






              share|improve this answer





















              • 2





                This only works if you're willing to add everything to version control. It also forces every change ever committed to be permanently stored, which may be undesirable.

                – Qudit
                May 16 '15 at 21:58











              • @Qudit, that is true, although it is possible via cloning to limit the history, but limiting the history is not (yet ?) implemented in Git by default.

                – switch87
                May 16 '15 at 22:07











              • @switch87 Yes, I know you can delete old commits. Version control is not really an appropriate solution for generic backups imo though, especially if there are large binary files.

                – Qudit
                May 16 '15 at 22:10











              • His question is for local backup, but if you use it for remote backup you can still use git annex for the bigger files. for local backup this is not a problem.

                – switch87
                May 16 '15 at 22:22






              • 2





                @switch87 This really should've been a comment to the Q and not an answer since it doesn't explain how you'd use git to do backups.

                – slm
                May 17 '15 at 11:35














              0












              0








              0







              This is not completely the same as what you ask for, but you could considered using a version-control tool. Tools like Git do everything you ask for, and more, especially if you do not work in folder B directly it could be interesting to take a look at it. you can find some more information on git here






              share|improve this answer















              This is not completely the same as what you ask for, but you could considered using a version-control tool. Tools like Git do everything you ask for, and more, especially if you do not work in folder B directly it could be interesting to take a look at it. you can find some more information on git here







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 16 '15 at 21:54

























              answered May 16 '15 at 21:21









              switch87switch87

              525316




              525316








              • 2





                This only works if you're willing to add everything to version control. It also forces every change ever committed to be permanently stored, which may be undesirable.

                – Qudit
                May 16 '15 at 21:58











              • @Qudit, that is true, although it is possible via cloning to limit the history, but limiting the history is not (yet ?) implemented in Git by default.

                – switch87
                May 16 '15 at 22:07











              • @switch87 Yes, I know you can delete old commits. Version control is not really an appropriate solution for generic backups imo though, especially if there are large binary files.

                – Qudit
                May 16 '15 at 22:10











              • His question is for local backup, but if you use it for remote backup you can still use git annex for the bigger files. for local backup this is not a problem.

                – switch87
                May 16 '15 at 22:22






              • 2





                @switch87 This really should've been a comment to the Q and not an answer since it doesn't explain how you'd use git to do backups.

                – slm
                May 17 '15 at 11:35














              • 2





                This only works if you're willing to add everything to version control. It also forces every change ever committed to be permanently stored, which may be undesirable.

                – Qudit
                May 16 '15 at 21:58











              • @Qudit, that is true, although it is possible via cloning to limit the history, but limiting the history is not (yet ?) implemented in Git by default.

                – switch87
                May 16 '15 at 22:07











              • @switch87 Yes, I know you can delete old commits. Version control is not really an appropriate solution for generic backups imo though, especially if there are large binary files.

                – Qudit
                May 16 '15 at 22:10











              • His question is for local backup, but if you use it for remote backup you can still use git annex for the bigger files. for local backup this is not a problem.

                – switch87
                May 16 '15 at 22:22






              • 2





                @switch87 This really should've been a comment to the Q and not an answer since it doesn't explain how you'd use git to do backups.

                – slm
                May 17 '15 at 11:35








              2




              2





              This only works if you're willing to add everything to version control. It also forces every change ever committed to be permanently stored, which may be undesirable.

              – Qudit
              May 16 '15 at 21:58





              This only works if you're willing to add everything to version control. It also forces every change ever committed to be permanently stored, which may be undesirable.

              – Qudit
              May 16 '15 at 21:58













              @Qudit, that is true, although it is possible via cloning to limit the history, but limiting the history is not (yet ?) implemented in Git by default.

              – switch87
              May 16 '15 at 22:07





              @Qudit, that is true, although it is possible via cloning to limit the history, but limiting the history is not (yet ?) implemented in Git by default.

              – switch87
              May 16 '15 at 22:07













              @switch87 Yes, I know you can delete old commits. Version control is not really an appropriate solution for generic backups imo though, especially if there are large binary files.

              – Qudit
              May 16 '15 at 22:10





              @switch87 Yes, I know you can delete old commits. Version control is not really an appropriate solution for generic backups imo though, especially if there are large binary files.

              – Qudit
              May 16 '15 at 22:10













              His question is for local backup, but if you use it for remote backup you can still use git annex for the bigger files. for local backup this is not a problem.

              – switch87
              May 16 '15 at 22:22





              His question is for local backup, but if you use it for remote backup you can still use git annex for the bigger files. for local backup this is not a problem.

              – switch87
              May 16 '15 at 22:22




              2




              2





              @switch87 This really should've been a comment to the Q and not an answer since it doesn't explain how you'd use git to do backups.

              – slm
              May 17 '15 at 11:35





              @switch87 This really should've been a comment to the Q and not an answer since it doesn't explain how you'd use git to do backups.

              – slm
              May 17 '15 at 11:35











              0














              You can use it this way:



              rsync -avu --delete /home/user/A/* /home/user/B/


              This way you will copy the content of folder A into folder B, not the content of folder A itself.






              share|improve this answer






























                0














                You can use it this way:



                rsync -avu --delete /home/user/A/* /home/user/B/


                This way you will copy the content of folder A into folder B, not the content of folder A itself.






                share|improve this answer




























                  0












                  0








                  0







                  You can use it this way:



                  rsync -avu --delete /home/user/A/* /home/user/B/


                  This way you will copy the content of folder A into folder B, not the content of folder A itself.






                  share|improve this answer















                  You can use it this way:



                  rsync -avu --delete /home/user/A/* /home/user/B/


                  This way you will copy the content of folder A into folder B, not the content of folder A itself.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 24 '18 at 15:47







                  user88036

















                  answered Sep 24 '18 at 15:38









                  Isaias SanchezIsaias Sanchez

                  1




                  1






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f203846%2fhow-to-sync-two-folders-with-command-line-tools%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How to make a Squid Proxy server?

                      Is this a new Fibonacci Identity?

                      Touch on Surface Book