Understanding of diff output

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
57
down vote

favorite
29












I have file1.txt



this is the original text 
line2
line3
line4
happy hacking !


and file2.txt



this is the original text 
line2
line4
happy hacking !
GNU is not UNIX


if I do: diff file1.txt file2.txt I get:



3d2 
< line3
5a5
> GNU is not UNIX


How is the output generally interpreted? I think that < means removed but what do 3d2 or 5a5 mean?



If I do:



$ diff -u file1.txt file2.txt 
--- file1.txt 2013-07-06 17:44:59.180000000 +0200
+++ file2.txt 2013-07-06 17:39:53.433000000 +0200
@@ -1,5 +1,5 @@
this is the original text
line2
-line3
line4
happy hacking !
+GNU is not UNIX


The results are clearer but what does @@ -1,5 +1,5 @@ mean?










share|improve this question



























    up vote
    57
    down vote

    favorite
    29












    I have file1.txt



    this is the original text 
    line2
    line3
    line4
    happy hacking !


    and file2.txt



    this is the original text 
    line2
    line4
    happy hacking !
    GNU is not UNIX


    if I do: diff file1.txt file2.txt I get:



    3d2 
    < line3
    5a5
    > GNU is not UNIX


    How is the output generally interpreted? I think that < means removed but what do 3d2 or 5a5 mean?



    If I do:



    $ diff -u file1.txt file2.txt 
    --- file1.txt 2013-07-06 17:44:59.180000000 +0200
    +++ file2.txt 2013-07-06 17:39:53.433000000 +0200
    @@ -1,5 +1,5 @@
    this is the original text
    line2
    -line3
    line4
    happy hacking !
    +GNU is not UNIX


    The results are clearer but what does @@ -1,5 +1,5 @@ mean?










    share|improve this question

























      up vote
      57
      down vote

      favorite
      29









      up vote
      57
      down vote

      favorite
      29






      29





      I have file1.txt



      this is the original text 
      line2
      line3
      line4
      happy hacking !


      and file2.txt



      this is the original text 
      line2
      line4
      happy hacking !
      GNU is not UNIX


      if I do: diff file1.txt file2.txt I get:



      3d2 
      < line3
      5a5
      > GNU is not UNIX


      How is the output generally interpreted? I think that < means removed but what do 3d2 or 5a5 mean?



      If I do:



      $ diff -u file1.txt file2.txt 
      --- file1.txt 2013-07-06 17:44:59.180000000 +0200
      +++ file2.txt 2013-07-06 17:39:53.433000000 +0200
      @@ -1,5 +1,5 @@
      this is the original text
      line2
      -line3
      line4
      happy hacking !
      +GNU is not UNIX


      The results are clearer but what does @@ -1,5 +1,5 @@ mean?










      share|improve this question















      I have file1.txt



      this is the original text 
      line2
      line3
      line4
      happy hacking !


      and file2.txt



      this is the original text 
      line2
      line4
      happy hacking !
      GNU is not UNIX


      if I do: diff file1.txt file2.txt I get:



      3d2 
      < line3
      5a5
      > GNU is not UNIX


      How is the output generally interpreted? I think that < means removed but what do 3d2 or 5a5 mean?



      If I do:



      $ diff -u file1.txt file2.txt 
      --- file1.txt 2013-07-06 17:44:59.180000000 +0200
      +++ file2.txt 2013-07-06 17:39:53.433000000 +0200
      @@ -1,5 +1,5 @@
      this is the original text
      line2
      -line3
      line4
      happy hacking !
      +GNU is not UNIX


      The results are clearer but what does @@ -1,5 +1,5 @@ mean?







      linux files diff






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 '16 at 2:54









      Jeff Schaller

      36.9k1052121




      36.9k1052121










      asked Jul 6 '13 at 15:47









      Jim

      2,851123457




      2,851123457




















          5 Answers
          5






          active

          oldest

          votes

















          up vote
          74
          down vote













          In your first diff output (so called "normall diff") the meaning is as follows



          < - denotes lines in file1.txt



          > - denotes lines in file2.txt



          3d2 and 5a5 denote line numbers affected and which actions were performed. d stands for deletion, a stands for adding (and c stands for changing). the number on the left of the character is the line number in file1.txt, the number on the right is the line number in file2.txt. So 3d2 tells you that the 3rd line in file1.txt was deleted and has the line number 2 in file2.txt (or better to say that after deletion the line counter went back to line number 2). 5a5 tells you that the we started from line number 5 in file1.txt (which was actually empty after we deleted a line in previous action), added the line and this added line is the number 5 in file2.txt.



          The output of diff -u command is formatted a bit differently (so called "unified diff" format). Here diff shows us a single piece of the text, instead of two separate texts. In the line @@ -1,5 +1,5 @@ the part -1,5 relates to file1.txt and the part +1,5 to file2.txt. They tell us that diff will show a piece of text, which is 5 lines long starting from line number 1 in file1.txt. And the same about the file2.txt - diff shows us 5 lines starting from line 1.



          As I have already said, the lines from both files are shown together



           this is the original text 
          line2
          -line3
          line4
          happy hacking !
          +GNU is not UNIX


          Here - denotes the lines, which were deleted from file1.txt and + denotes the lines, which were added.






          share|improve this answer



























            up vote
            17
            down vote













            Summary:



            Given a diff file1 file2, < means the line is missing in file2 and >means the line is missing in file1. The 3d2 and 5a5 can be ignored, they are commands for patch which is often used with diff.



            Full Answer:



            Many *nix utilities offer TeXinfo manuals as well as the simpler man pages. you can access these by running info command, for example info diff. In this case, the section your are interested in is:




            2.4.2 Detailed Description of Normal Format




            The normal output format consists of one or more hunks of differences;
            each hunk shows one area where the files differ. Normal format hunks
            look like this:




             CHANGE-COMMAND
            < FROM-FILE-LINE
            < FROM-FILE-LINE...
            ---
            > TO-FILE-LINE
            > TO-FILE-LINE...



            There are three types of change commands. Each consists of a line
            number or comma-separated range of lines in the first file, a single
            character indicating the kind of change to make, and a line number or
            comma-separated range of lines in the second file. All line numbers
            are the original line numbers in each file. The types of change
            commands are:




            `LaR'
            Add the lines in range R of the second file after line L of the
            first file. For example, `8a12,15' means append lines 12-15 of
            file 2 after line 8 of file 1; or, if changing file 2 into file 1,
            delete lines 12-15 of file 2.

            `FcT'
            Replace the lines in range F of the first file with lines in range
            T of the second file. This is like a combined add and delete, but
            more compact. For example, `5,7c8,10' means change lines 5-7 of
            file 1 to read as lines 8-10 of file 2; or, if changing file 2 into
            file 1, change lines 8-10 of file 2 to read as lines 5-7 of file 1.

            `RdL'
            Delete the lines in range R from the first file; line L is where
            they would have appeared in the second file had they not been





            share|improve this answer



























              up vote
              3
              down vote













              I suggest to use:



              diff -rupP file1.txt file2.txt > result.patch



              Then, when you read result.patch, you will instantly know the difference.



              These are the meanings of the command line switches:



              -r: recursive



              -u: shows line number



              -p(small): shows differences in C functions



              -P(capital): in case of multiple files the full path is shown






              share|improve this answer





























                up vote
                1
                down vote













                The above answers are good. However as a beginner, I found them slightly difficult to understand and upon searching further, I found a very useful link:
                Linux Diff Command & Examples



                The site explains the concept in a simple and easy to understand manner.



                Diff command is easier to understand if you consider it this way :




                Essentially, it outputs a set of instructions for how to change one
                file to make it identical to the second file.




                Each of the following cases are explained well:




                a for add, c for change, d for delete







                share|improve this answer



























                  up vote
                  0
                  down vote













                  Rename things to help you remember!



                  diff <file-to-edit> <file-with-updates> #Rather than diff f1 f2


                  The results operate on the file-to-edit (file1), applying various updates to it.




                  Similarity, I find these renames helpful to conceptualize the results:



                  Delete='remove' & Add='insert'.



                  2,4d1 --- D(s)-d-N --- delete ('remove') D line(s). Then sync at line N in both.



                  4a2,4 --- N-a-U(s) --- At line N, add ('insert') update's line(s) U



                  Note: They're nearly symmetric.




                  Change= 'remove & insert'.



                  2,4c5,6 --- R(s)-c-U(s) --- Remove R(s) lines, then insert updated lines U(s) in their place.





                  For example:



                  4a2,4 --- starting at 4, add updated lines 2-4 (i.e. 2,4 means 2, 3 and 4)



                  2,4d1 --- remove lines 2-4.



                  2,4c5,6 --- remove lines 2-4, and insert updated lines 5-6




                  • I know that these are stream editor commands, and designed to be processed by a machine. For example, it really is the ed command add, not insert, but it's more helpful for me to think of insert which is what in the end is being done to the file. They use stream operations, but I like to think in terms of results.






                  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',
                    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%2f81998%2funderstanding-of-diff-output%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown

























                    5 Answers
                    5






                    active

                    oldest

                    votes








                    5 Answers
                    5






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes








                    up vote
                    74
                    down vote













                    In your first diff output (so called "normall diff") the meaning is as follows



                    < - denotes lines in file1.txt



                    > - denotes lines in file2.txt



                    3d2 and 5a5 denote line numbers affected and which actions were performed. d stands for deletion, a stands for adding (and c stands for changing). the number on the left of the character is the line number in file1.txt, the number on the right is the line number in file2.txt. So 3d2 tells you that the 3rd line in file1.txt was deleted and has the line number 2 in file2.txt (or better to say that after deletion the line counter went back to line number 2). 5a5 tells you that the we started from line number 5 in file1.txt (which was actually empty after we deleted a line in previous action), added the line and this added line is the number 5 in file2.txt.



                    The output of diff -u command is formatted a bit differently (so called "unified diff" format). Here diff shows us a single piece of the text, instead of two separate texts. In the line @@ -1,5 +1,5 @@ the part -1,5 relates to file1.txt and the part +1,5 to file2.txt. They tell us that diff will show a piece of text, which is 5 lines long starting from line number 1 in file1.txt. And the same about the file2.txt - diff shows us 5 lines starting from line 1.



                    As I have already said, the lines from both files are shown together



                     this is the original text 
                    line2
                    -line3
                    line4
                    happy hacking !
                    +GNU is not UNIX


                    Here - denotes the lines, which were deleted from file1.txt and + denotes the lines, which were added.






                    share|improve this answer
























                      up vote
                      74
                      down vote













                      In your first diff output (so called "normall diff") the meaning is as follows



                      < - denotes lines in file1.txt



                      > - denotes lines in file2.txt



                      3d2 and 5a5 denote line numbers affected and which actions were performed. d stands for deletion, a stands for adding (and c stands for changing). the number on the left of the character is the line number in file1.txt, the number on the right is the line number in file2.txt. So 3d2 tells you that the 3rd line in file1.txt was deleted and has the line number 2 in file2.txt (or better to say that after deletion the line counter went back to line number 2). 5a5 tells you that the we started from line number 5 in file1.txt (which was actually empty after we deleted a line in previous action), added the line and this added line is the number 5 in file2.txt.



                      The output of diff -u command is formatted a bit differently (so called "unified diff" format). Here diff shows us a single piece of the text, instead of two separate texts. In the line @@ -1,5 +1,5 @@ the part -1,5 relates to file1.txt and the part +1,5 to file2.txt. They tell us that diff will show a piece of text, which is 5 lines long starting from line number 1 in file1.txt. And the same about the file2.txt - diff shows us 5 lines starting from line 1.



                      As I have already said, the lines from both files are shown together



                       this is the original text 
                      line2
                      -line3
                      line4
                      happy hacking !
                      +GNU is not UNIX


                      Here - denotes the lines, which were deleted from file1.txt and + denotes the lines, which were added.






                      share|improve this answer






















                        up vote
                        74
                        down vote










                        up vote
                        74
                        down vote









                        In your first diff output (so called "normall diff") the meaning is as follows



                        < - denotes lines in file1.txt



                        > - denotes lines in file2.txt



                        3d2 and 5a5 denote line numbers affected and which actions were performed. d stands for deletion, a stands for adding (and c stands for changing). the number on the left of the character is the line number in file1.txt, the number on the right is the line number in file2.txt. So 3d2 tells you that the 3rd line in file1.txt was deleted and has the line number 2 in file2.txt (or better to say that after deletion the line counter went back to line number 2). 5a5 tells you that the we started from line number 5 in file1.txt (which was actually empty after we deleted a line in previous action), added the line and this added line is the number 5 in file2.txt.



                        The output of diff -u command is formatted a bit differently (so called "unified diff" format). Here diff shows us a single piece of the text, instead of two separate texts. In the line @@ -1,5 +1,5 @@ the part -1,5 relates to file1.txt and the part +1,5 to file2.txt. They tell us that diff will show a piece of text, which is 5 lines long starting from line number 1 in file1.txt. And the same about the file2.txt - diff shows us 5 lines starting from line 1.



                        As I have already said, the lines from both files are shown together



                         this is the original text 
                        line2
                        -line3
                        line4
                        happy hacking !
                        +GNU is not UNIX


                        Here - denotes the lines, which were deleted from file1.txt and + denotes the lines, which were added.






                        share|improve this answer












                        In your first diff output (so called "normall diff") the meaning is as follows



                        < - denotes lines in file1.txt



                        > - denotes lines in file2.txt



                        3d2 and 5a5 denote line numbers affected and which actions were performed. d stands for deletion, a stands for adding (and c stands for changing). the number on the left of the character is the line number in file1.txt, the number on the right is the line number in file2.txt. So 3d2 tells you that the 3rd line in file1.txt was deleted and has the line number 2 in file2.txt (or better to say that after deletion the line counter went back to line number 2). 5a5 tells you that the we started from line number 5 in file1.txt (which was actually empty after we deleted a line in previous action), added the line and this added line is the number 5 in file2.txt.



                        The output of diff -u command is formatted a bit differently (so called "unified diff" format). Here diff shows us a single piece of the text, instead of two separate texts. In the line @@ -1,5 +1,5 @@ the part -1,5 relates to file1.txt and the part +1,5 to file2.txt. They tell us that diff will show a piece of text, which is 5 lines long starting from line number 1 in file1.txt. And the same about the file2.txt - diff shows us 5 lines starting from line 1.



                        As I have already said, the lines from both files are shown together



                         this is the original text 
                        line2
                        -line3
                        line4
                        happy hacking !
                        +GNU is not UNIX


                        Here - denotes the lines, which were deleted from file1.txt and + denotes the lines, which were added.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Jul 15 '15 at 9:35









                        John Smith

                        1,08867




                        1,08867






















                            up vote
                            17
                            down vote













                            Summary:



                            Given a diff file1 file2, < means the line is missing in file2 and >means the line is missing in file1. The 3d2 and 5a5 can be ignored, they are commands for patch which is often used with diff.



                            Full Answer:



                            Many *nix utilities offer TeXinfo manuals as well as the simpler man pages. you can access these by running info command, for example info diff. In this case, the section your are interested in is:




                            2.4.2 Detailed Description of Normal Format




                            The normal output format consists of one or more hunks of differences;
                            each hunk shows one area where the files differ. Normal format hunks
                            look like this:




                             CHANGE-COMMAND
                            < FROM-FILE-LINE
                            < FROM-FILE-LINE...
                            ---
                            > TO-FILE-LINE
                            > TO-FILE-LINE...



                            There are three types of change commands. Each consists of a line
                            number or comma-separated range of lines in the first file, a single
                            character indicating the kind of change to make, and a line number or
                            comma-separated range of lines in the second file. All line numbers
                            are the original line numbers in each file. The types of change
                            commands are:




                            `LaR'
                            Add the lines in range R of the second file after line L of the
                            first file. For example, `8a12,15' means append lines 12-15 of
                            file 2 after line 8 of file 1; or, if changing file 2 into file 1,
                            delete lines 12-15 of file 2.

                            `FcT'
                            Replace the lines in range F of the first file with lines in range
                            T of the second file. This is like a combined add and delete, but
                            more compact. For example, `5,7c8,10' means change lines 5-7 of
                            file 1 to read as lines 8-10 of file 2; or, if changing file 2 into
                            file 1, change lines 8-10 of file 2 to read as lines 5-7 of file 1.

                            `RdL'
                            Delete the lines in range R from the first file; line L is where
                            they would have appeared in the second file had they not been





                            share|improve this answer
























                              up vote
                              17
                              down vote













                              Summary:



                              Given a diff file1 file2, < means the line is missing in file2 and >means the line is missing in file1. The 3d2 and 5a5 can be ignored, they are commands for patch which is often used with diff.



                              Full Answer:



                              Many *nix utilities offer TeXinfo manuals as well as the simpler man pages. you can access these by running info command, for example info diff. In this case, the section your are interested in is:




                              2.4.2 Detailed Description of Normal Format




                              The normal output format consists of one or more hunks of differences;
                              each hunk shows one area where the files differ. Normal format hunks
                              look like this:




                               CHANGE-COMMAND
                              < FROM-FILE-LINE
                              < FROM-FILE-LINE...
                              ---
                              > TO-FILE-LINE
                              > TO-FILE-LINE...



                              There are three types of change commands. Each consists of a line
                              number or comma-separated range of lines in the first file, a single
                              character indicating the kind of change to make, and a line number or
                              comma-separated range of lines in the second file. All line numbers
                              are the original line numbers in each file. The types of change
                              commands are:




                              `LaR'
                              Add the lines in range R of the second file after line L of the
                              first file. For example, `8a12,15' means append lines 12-15 of
                              file 2 after line 8 of file 1; or, if changing file 2 into file 1,
                              delete lines 12-15 of file 2.

                              `FcT'
                              Replace the lines in range F of the first file with lines in range
                              T of the second file. This is like a combined add and delete, but
                              more compact. For example, `5,7c8,10' means change lines 5-7 of
                              file 1 to read as lines 8-10 of file 2; or, if changing file 2 into
                              file 1, change lines 8-10 of file 2 to read as lines 5-7 of file 1.

                              `RdL'
                              Delete the lines in range R from the first file; line L is where
                              they would have appeared in the second file had they not been





                              share|improve this answer






















                                up vote
                                17
                                down vote










                                up vote
                                17
                                down vote









                                Summary:



                                Given a diff file1 file2, < means the line is missing in file2 and >means the line is missing in file1. The 3d2 and 5a5 can be ignored, they are commands for patch which is often used with diff.



                                Full Answer:



                                Many *nix utilities offer TeXinfo manuals as well as the simpler man pages. you can access these by running info command, for example info diff. In this case, the section your are interested in is:




                                2.4.2 Detailed Description of Normal Format




                                The normal output format consists of one or more hunks of differences;
                                each hunk shows one area where the files differ. Normal format hunks
                                look like this:




                                 CHANGE-COMMAND
                                < FROM-FILE-LINE
                                < FROM-FILE-LINE...
                                ---
                                > TO-FILE-LINE
                                > TO-FILE-LINE...



                                There are three types of change commands. Each consists of a line
                                number or comma-separated range of lines in the first file, a single
                                character indicating the kind of change to make, and a line number or
                                comma-separated range of lines in the second file. All line numbers
                                are the original line numbers in each file. The types of change
                                commands are:




                                `LaR'
                                Add the lines in range R of the second file after line L of the
                                first file. For example, `8a12,15' means append lines 12-15 of
                                file 2 after line 8 of file 1; or, if changing file 2 into file 1,
                                delete lines 12-15 of file 2.

                                `FcT'
                                Replace the lines in range F of the first file with lines in range
                                T of the second file. This is like a combined add and delete, but
                                more compact. For example, `5,7c8,10' means change lines 5-7 of
                                file 1 to read as lines 8-10 of file 2; or, if changing file 2 into
                                file 1, change lines 8-10 of file 2 to read as lines 5-7 of file 1.

                                `RdL'
                                Delete the lines in range R from the first file; line L is where
                                they would have appeared in the second file had they not been





                                share|improve this answer












                                Summary:



                                Given a diff file1 file2, < means the line is missing in file2 and >means the line is missing in file1. The 3d2 and 5a5 can be ignored, they are commands for patch which is often used with diff.



                                Full Answer:



                                Many *nix utilities offer TeXinfo manuals as well as the simpler man pages. you can access these by running info command, for example info diff. In this case, the section your are interested in is:




                                2.4.2 Detailed Description of Normal Format




                                The normal output format consists of one or more hunks of differences;
                                each hunk shows one area where the files differ. Normal format hunks
                                look like this:




                                 CHANGE-COMMAND
                                < FROM-FILE-LINE
                                < FROM-FILE-LINE...
                                ---
                                > TO-FILE-LINE
                                > TO-FILE-LINE...



                                There are three types of change commands. Each consists of a line
                                number or comma-separated range of lines in the first file, a single
                                character indicating the kind of change to make, and a line number or
                                comma-separated range of lines in the second file. All line numbers
                                are the original line numbers in each file. The types of change
                                commands are:




                                `LaR'
                                Add the lines in range R of the second file after line L of the
                                first file. For example, `8a12,15' means append lines 12-15 of
                                file 2 after line 8 of file 1; or, if changing file 2 into file 1,
                                delete lines 12-15 of file 2.

                                `FcT'
                                Replace the lines in range F of the first file with lines in range
                                T of the second file. This is like a combined add and delete, but
                                more compact. For example, `5,7c8,10' means change lines 5-7 of
                                file 1 to read as lines 8-10 of file 2; or, if changing file 2 into
                                file 1, change lines 8-10 of file 2 to read as lines 5-7 of file 1.

                                `RdL'
                                Delete the lines in range R from the first file; line L is where
                                they would have appeared in the second file had they not been






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jul 6 '13 at 16:29









                                terdon

                                126k31244419




                                126k31244419




















                                    up vote
                                    3
                                    down vote













                                    I suggest to use:



                                    diff -rupP file1.txt file2.txt > result.patch



                                    Then, when you read result.patch, you will instantly know the difference.



                                    These are the meanings of the command line switches:



                                    -r: recursive



                                    -u: shows line number



                                    -p(small): shows differences in C functions



                                    -P(capital): in case of multiple files the full path is shown






                                    share|improve this answer


























                                      up vote
                                      3
                                      down vote













                                      I suggest to use:



                                      diff -rupP file1.txt file2.txt > result.patch



                                      Then, when you read result.patch, you will instantly know the difference.



                                      These are the meanings of the command line switches:



                                      -r: recursive



                                      -u: shows line number



                                      -p(small): shows differences in C functions



                                      -P(capital): in case of multiple files the full path is shown






                                      share|improve this answer
























                                        up vote
                                        3
                                        down vote










                                        up vote
                                        3
                                        down vote









                                        I suggest to use:



                                        diff -rupP file1.txt file2.txt > result.patch



                                        Then, when you read result.patch, you will instantly know the difference.



                                        These are the meanings of the command line switches:



                                        -r: recursive



                                        -u: shows line number



                                        -p(small): shows differences in C functions



                                        -P(capital): in case of multiple files the full path is shown






                                        share|improve this answer














                                        I suggest to use:



                                        diff -rupP file1.txt file2.txt > result.patch



                                        Then, when you read result.patch, you will instantly know the difference.



                                        These are the meanings of the command line switches:



                                        -r: recursive



                                        -u: shows line number



                                        -p(small): shows differences in C functions



                                        -P(capital): in case of multiple files the full path is shown







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Jan 5 at 12:06









                                        runlevel0

                                        25819




                                        25819










                                        answered Jul 15 '15 at 11:03









                                        Ravi

                                        334




                                        334




















                                            up vote
                                            1
                                            down vote













                                            The above answers are good. However as a beginner, I found them slightly difficult to understand and upon searching further, I found a very useful link:
                                            Linux Diff Command & Examples



                                            The site explains the concept in a simple and easy to understand manner.



                                            Diff command is easier to understand if you consider it this way :




                                            Essentially, it outputs a set of instructions for how to change one
                                            file to make it identical to the second file.




                                            Each of the following cases are explained well:




                                            a for add, c for change, d for delete







                                            share|improve this answer
























                                              up vote
                                              1
                                              down vote













                                              The above answers are good. However as a beginner, I found them slightly difficult to understand and upon searching further, I found a very useful link:
                                              Linux Diff Command & Examples



                                              The site explains the concept in a simple and easy to understand manner.



                                              Diff command is easier to understand if you consider it this way :




                                              Essentially, it outputs a set of instructions for how to change one
                                              file to make it identical to the second file.




                                              Each of the following cases are explained well:




                                              a for add, c for change, d for delete







                                              share|improve this answer






















                                                up vote
                                                1
                                                down vote










                                                up vote
                                                1
                                                down vote









                                                The above answers are good. However as a beginner, I found them slightly difficult to understand and upon searching further, I found a very useful link:
                                                Linux Diff Command & Examples



                                                The site explains the concept in a simple and easy to understand manner.



                                                Diff command is easier to understand if you consider it this way :




                                                Essentially, it outputs a set of instructions for how to change one
                                                file to make it identical to the second file.




                                                Each of the following cases are explained well:




                                                a for add, c for change, d for delete







                                                share|improve this answer












                                                The above answers are good. However as a beginner, I found them slightly difficult to understand and upon searching further, I found a very useful link:
                                                Linux Diff Command & Examples



                                                The site explains the concept in a simple and easy to understand manner.



                                                Diff command is easier to understand if you consider it this way :




                                                Essentially, it outputs a set of instructions for how to change one
                                                file to make it identical to the second file.




                                                Each of the following cases are explained well:




                                                a for add, c for change, d for delete








                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Apr 23 at 7:34









                                                userAsh

                                                111




                                                111




















                                                    up vote
                                                    0
                                                    down vote













                                                    Rename things to help you remember!



                                                    diff <file-to-edit> <file-with-updates> #Rather than diff f1 f2


                                                    The results operate on the file-to-edit (file1), applying various updates to it.




                                                    Similarity, I find these renames helpful to conceptualize the results:



                                                    Delete='remove' & Add='insert'.



                                                    2,4d1 --- D(s)-d-N --- delete ('remove') D line(s). Then sync at line N in both.



                                                    4a2,4 --- N-a-U(s) --- At line N, add ('insert') update's line(s) U



                                                    Note: They're nearly symmetric.




                                                    Change= 'remove & insert'.



                                                    2,4c5,6 --- R(s)-c-U(s) --- Remove R(s) lines, then insert updated lines U(s) in their place.





                                                    For example:



                                                    4a2,4 --- starting at 4, add updated lines 2-4 (i.e. 2,4 means 2, 3 and 4)



                                                    2,4d1 --- remove lines 2-4.



                                                    2,4c5,6 --- remove lines 2-4, and insert updated lines 5-6




                                                    • I know that these are stream editor commands, and designed to be processed by a machine. For example, it really is the ed command add, not insert, but it's more helpful for me to think of insert which is what in the end is being done to the file. They use stream operations, but I like to think in terms of results.






                                                    share|improve this answer


























                                                      up vote
                                                      0
                                                      down vote













                                                      Rename things to help you remember!



                                                      diff <file-to-edit> <file-with-updates> #Rather than diff f1 f2


                                                      The results operate on the file-to-edit (file1), applying various updates to it.




                                                      Similarity, I find these renames helpful to conceptualize the results:



                                                      Delete='remove' & Add='insert'.



                                                      2,4d1 --- D(s)-d-N --- delete ('remove') D line(s). Then sync at line N in both.



                                                      4a2,4 --- N-a-U(s) --- At line N, add ('insert') update's line(s) U



                                                      Note: They're nearly symmetric.




                                                      Change= 'remove & insert'.



                                                      2,4c5,6 --- R(s)-c-U(s) --- Remove R(s) lines, then insert updated lines U(s) in their place.





                                                      For example:



                                                      4a2,4 --- starting at 4, add updated lines 2-4 (i.e. 2,4 means 2, 3 and 4)



                                                      2,4d1 --- remove lines 2-4.



                                                      2,4c5,6 --- remove lines 2-4, and insert updated lines 5-6




                                                      • I know that these are stream editor commands, and designed to be processed by a machine. For example, it really is the ed command add, not insert, but it's more helpful for me to think of insert which is what in the end is being done to the file. They use stream operations, but I like to think in terms of results.






                                                      share|improve this answer
























                                                        up vote
                                                        0
                                                        down vote










                                                        up vote
                                                        0
                                                        down vote









                                                        Rename things to help you remember!



                                                        diff <file-to-edit> <file-with-updates> #Rather than diff f1 f2


                                                        The results operate on the file-to-edit (file1), applying various updates to it.




                                                        Similarity, I find these renames helpful to conceptualize the results:



                                                        Delete='remove' & Add='insert'.



                                                        2,4d1 --- D(s)-d-N --- delete ('remove') D line(s). Then sync at line N in both.



                                                        4a2,4 --- N-a-U(s) --- At line N, add ('insert') update's line(s) U



                                                        Note: They're nearly symmetric.




                                                        Change= 'remove & insert'.



                                                        2,4c5,6 --- R(s)-c-U(s) --- Remove R(s) lines, then insert updated lines U(s) in their place.





                                                        For example:



                                                        4a2,4 --- starting at 4, add updated lines 2-4 (i.e. 2,4 means 2, 3 and 4)



                                                        2,4d1 --- remove lines 2-4.



                                                        2,4c5,6 --- remove lines 2-4, and insert updated lines 5-6




                                                        • I know that these are stream editor commands, and designed to be processed by a machine. For example, it really is the ed command add, not insert, but it's more helpful for me to think of insert which is what in the end is being done to the file. They use stream operations, but I like to think in terms of results.






                                                        share|improve this answer














                                                        Rename things to help you remember!



                                                        diff <file-to-edit> <file-with-updates> #Rather than diff f1 f2


                                                        The results operate on the file-to-edit (file1), applying various updates to it.




                                                        Similarity, I find these renames helpful to conceptualize the results:



                                                        Delete='remove' & Add='insert'.



                                                        2,4d1 --- D(s)-d-N --- delete ('remove') D line(s). Then sync at line N in both.



                                                        4a2,4 --- N-a-U(s) --- At line N, add ('insert') update's line(s) U



                                                        Note: They're nearly symmetric.




                                                        Change= 'remove & insert'.



                                                        2,4c5,6 --- R(s)-c-U(s) --- Remove R(s) lines, then insert updated lines U(s) in their place.





                                                        For example:



                                                        4a2,4 --- starting at 4, add updated lines 2-4 (i.e. 2,4 means 2, 3 and 4)



                                                        2,4d1 --- remove lines 2-4.



                                                        2,4c5,6 --- remove lines 2-4, and insert updated lines 5-6




                                                        • I know that these are stream editor commands, and designed to be processed by a machine. For example, it really is the ed command add, not insert, but it's more helpful for me to think of insert which is what in the end is being done to the file. They use stream operations, but I like to think in terms of results.







                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited Nov 23 at 0:14

























                                                        answered Nov 22 at 23:48









                                                        Eliptical view

                                                        5191620




                                                        5191620



























                                                            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.





                                                            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                            Please pay close attention to the following guidance:


                                                            • 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%2f81998%2funderstanding-of-diff-output%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 check contact read email or not when send email to Individual?

                                                            Displaying single band from multi-band raster using QGIS

                                                            How many registers does an x86_64 CPU actually have?