diff (compare two text files)
Compares the contents of two text files. Displays the lines that are different. Format: diff fileordirname1 fileordirname2
Examples: diff prog1 prog2
diff prog1 /home/janet/dir1
diff /home/janet /home/janet/dir1
Compares prog1 to prog2. In the second example, compares prog1 to /home/janet/dir1/prog1 if it exists. In the third example, compares all files that exist in both directories. Displays the lines that differ between the two files. < indicates lines from the first file; > indicates lines from the second file. For example: cat fileA
John Smith
Alice Brown
John Huang
cat fileB
Bob Smith
Alice in Wonderland
John Huang
diff fileA fileB
<John Smith
<Alice Brown
---
>Bob Smith
>Alice in Wonderland
Opt | What It Does | Example |
---|
-b | Treat groups of blanks as one | diff -b file1 file2 | -B | Ignore blank lines | diff -B prog1 prog2 | -c | Display 3 lines surrounding each changed line | diff -c file1 /home/janet | -C n | Display n lines surrounding each changed line | diff -C 5 file1 file1.bak | -i | Ignore case | diff -I report1 report2 | -r | Also compare subdirectories | diff -r /home/janet/home/bob | -w | Ignore all white space | diff -w file1 file2 | -y | Two-column output | diff -y file2 file5 | |