diff --git a/site/pages/cmd/advanced/diff.html b/site/pages/cmd/advanced/diff.html new file mode 100644 index 0000000..96007a5 --- /dev/null +++ b/site/pages/cmd/advanced/diff.html @@ -0,0 +1,168 @@ +--- +layout: page +author: Alessandro Luini +category-page: advanced +category-title: Advanced commands +tags: difference lines diff file separating +title: diff +--- + + + + + +

diff analyzes two files and prints the lines that are different. + Essentially, it outputs a set of instructions for how to change one file to + make it identical to the second file.

+ + + + + + + +

How to use

+ +

To activate the diff command, we must take as parameters two or more + files that we want to compare and it will give us the output of + different lines.
+ For example let's say we have two files, file1.txt and file2.txt.
+
If file1.txt contains the following four lines of text:

+ +
  1. I need to buy apples.
  2. +
  3. I need to run around the park.
  4. +
  5. I need to wash the dog.
  6. +
  7. I need to get the car detailed.
+ +

...and file2.txt contains these four lines:

+ +
  1. I need to buy apples.
  2. +
  3. I need to do the laundry.
  4. +
  5. I need to wash the dog.
  6. +
  7. I need to get the dog detailed.
+ +

...then we can use diff to automatically display for us which lines differ + between the two files with this command:

+ +
diff file1.txt file2.txt
+ +

...and the output will be:

+ +
 2,4c2,4 
+< I need to run the laundry.
+< I need to wash the dog.
+< I need to get the car detailed.
+---
+> I need to do the laundry.
+> I need to wash the car.
+> I need to get the dog detailed.
+ +

In our output above, "2,4c2,4" means: "Lines 2 through 4 in the first + file need to be changed to match lines 2 through 4 in the second file.

+ + + + + + + +

Flags

+