Skip to content

diff command

Compare files line by line.

On this page

Syntax

diff [options] file1 file2

Provided by the diffutils package. Run man diff for the full manual.

Common options

OptionWhat it does
-uUnified format (what git shows)
-ySide by side
-rCompare directories recursively
-qOnly say whether files differ
-iIgnore case
-wIgnore all whitespace
--colorColour the output

Examples

  1. Compare two files

    diff old.conf new.conf
  2. Unified diff

    diff -u old.conf new.conf
  3. Side by side

    diff -y --width=160 a.txt b.txt
  4. Compare directories

    diff -rq dir1/ dir2/
  5. Ignore whitespace

    diff -w a.py b.py
  6. Create a patch

    diff -u original.c fixed.c > fix.patch

diff guides

← All Linux commands · Suggest a fix

Back to top