diff

Diff Cheatsheet #

The GNU diff command compares files line by line and shows the differences between them.

Basic Commands #

Command/OptionExampleDescription
diffdiff file1.txt file2.txtCompare two files line by line
diff -udiff -u file1.txt file2.txtUnified format for differences (-u for unified)
diff -cdiff -c file1.txt file2.txtContext format for differences (-c for context)
diff -idiff -i file1.txt file2.txtIgnore case differences (-i for ignore case)
diff -wdiff -w file1.txt file2.txtIgnore all white space (-w for ignore white space)
diff -bdiff -b file1.txt file2.txtIgnore changes in the amount of white space (-b for ignore space changes)
diff -rdiff -r dir1 dir2Recursively compare directories (-r for recursive)
diff -Ndiff -N file1.txt file2.txtTreat absent files as empty (-N for new files)

Advanced Commands #

Command/OptionExampleDescription
diff -ydiff -y file1.txt file2.txtDisplay differences side by side (-y for side-by-side)
diff --side-by-sidediff --side-by-side file1.txt file2.txtDisplay differences side by side with --side-by-side
diff -u -pdiff -u -p file1.txt file2.txtUnified format with C function names (-p for C function names)
diff -qdiff -q file1.txt file2.txtReport only if files differ (-q for quiet)
diff -r -xdiff -r -x '*.log' dir1 dir2Exclude files matching a pattern when comparing directories (-x for exclude)
diff -u -Ndiff -u -N file1.txt file2.txtUnified format with treating absent files as empty (-N for new files)

This cheatsheet covers the essential GNU diff commands and options for comparing files and directories.

diff

Explore our comprehensive cheatsheets to enhance your knowledge and efficiency. Each cheatsheet provides detailed command options, examples, and descriptions to help you master various tools and technologies.