diff
- compare files in two directories, don't show common lines, output in 2 columns and ignore white space differences
diff -y -b --suppress-common path1 path2
- compare all files recursively, excluding any with a .pdf extension, and only print file names that differ
diff -r -q --exclude="*.pdf" path1 path2
- compare all files recursively, excluding any with a .pdf extension, and only print file names that differ, but suppress common subdirectory and Only in lines
diff -r -q --exclude="*.pdf" path1 path2 | grep -v -E '^Common subdirectories|^Only in'
alternative output formats
- unified
diff --unified file1.txt file2.txt
- context
diff --context file1.txt file2.txt
create patch file
- diff -Naur oldfile newfile > patchfile
- then, to patch an original, copy the patchfile beside the file to be updated, and patch it like this
patch -p0 < patchfile
count lines that are different
This outputs 2 columns, hiding lines that are the same, then pipes the result through the wc program with the flag to count newlines.
diff -y --suppress-common-lines file1.txt file2.txt | wc -l
help
The diff utility has a man page, but the more comprehensive documentation is available in info format (info diff).