"diff" Command

Learn all about diff command

HOME

diff - compare files line by line

When comparing two files, 'diff' finds sequences of lines common to both files, interspersed with groups of differing lines called hunks.

Comparing two identical files yields one sequence of common lines and no hunks, because no lines differ.

Comparing two entirely different files yields no common lines and one large hunk that contains all lines of both files.

In general, there are many ways to match up lines between two given files. `diff' tries to minimize the total hunk size by finding large sequences of common lines interspersed with small hunks of differing lines.

root:~# man diff
root:~# info diff
          

Following files will be used in examples.
root:~# cat file1.txt
I need flowers.
I need to buy oranges.
I need to run the dryer.
I need to wash the door.
I need to get the car detailed.
I need chocholates.
root:~#
root:~# cat file2.txt
I need to buy oranges.
I need to run the iron.
I need to wash the windows.
I need to get the car detailed.
I need to buy new phone.
root:~#
root:~# cat file3.txt
tiger
lion
hippo
elephant
root:~#
root:~# cat file4.txt
tiger
rhino
elephant
cheetah
root:~#