HxHippy

diff

Compare files line by line

Overview

Compares two files line by line and outputs the differences. It can also compare directories.

Syntax

diff [OPTION]... FILES

Common Options

-i, --ignore-case

Ignore case distinctions in file contents.

-w, --ignore-all-space

Ignore all white space.

-b, --ignore-space-change

Ignore changes in the amount of white space.

-B, --ignore-blank-lines

Ignore changes whose lines are all blank.

-u, -U NUM, --unified[=NUM]

Output NUM (default 3) lines of unified context. This is a common format for patches.

-c, -C NUM, --context[=NUM]

Output NUM (default 3) lines of copied context.

-r, --recursive

Recursively compare any subdirectories found.

-q, --brief

Report only when files differ.

--suppress-common-lines

Do not display common lines (useful with side-by-side).

-y, --side-by-side

Output in two columns.

Examples

$ diff file1.txt file2.txt

Compares file1.txt and file2.txt and shows the differences.

$ diff -u old_version.c new_version.c

Shows differences between two C files in unified format.

$ diff -i config_a.conf config_b.conf

Compares two config files, ignoring case.

$ diff -w document_v1.md document_v2.md

Compares two documents, ignoring all whitespace changes.

$ diff -r original_dir/ backup_dir/

Recursively compares the contents of original_dir/ and backup_dir/.

$ diff -q dir1/ dir2/

Reports only the names of files that differ between dir1/ and dir2/.

$ diff -y --suppress-common-lines main.py feature.py

Compares main.py and feature.py side-by-side, only showing differing lines.

differencecomparefiletextpatchdiff