diff — Create patches, view the differences between files
diff -u [other options] {old file} {new file}
To compare two files
diff -u some-file.old-version some-file.new-version
To compare two c program files (the -p gives function information)
diff -pu old-version-of-program.c new-version-of-program.c
To recursively compare and find which files differ between two directories
diff -r -brief directory-1 directory-2
To find the differences between the files in those two directories
diff -ru directory-1 directory-2
To save the differences between to files as a patch
diff -u old-file new-file > name-of.patch
Running diff on two files which contained
Hello there, world. How are things going?
and
Hello there, world! How are things going? The weather sure is awful.
would result in the following output
--- file-1.txt 2004-03-01 16:57:01.000000000 -0700 +++ file-2.txt 2004-03-01 16:57:06.000000000 -0700 @@ -1,2 +1,3 @@ -Hello there, world. +Hello there, world! How are things going? +The weather sure is awful.
The first two lines show which files are being compared. The third line specifies the lines in the two files that have differences. Finally, in the remaining lines: (1) If the first character is a space, then the line is the same for both files, (2) If the first character is a minus sign, then it is a line that appears in the first file, and (3) If the first character is a plus sign, then it is a line that appears in the second file.