diff
Topic: Text
Program: diff
Compares two files line by line.
Package: diff
Usage
diff [OPTION]... FILE1 FILE2
Description
Compare two files line by line and show what to change in FILE1 to get FILE2. Lines starting with < are only in FILE1, lines with > only in FILE2. A FILE can be a directory, then diff compares the file with the same name inside it, or with -r all files below it. Exit status 0: same, 1: different, 2: trouble.
Options in the simulator
-
--normal show the differences as lines to change, add and delete (the default) -
-q, --brief only say whether there is a difference, not what it is -
-s, --report-identical-files also print a line if both files have equal content -
-c show 3 lines of context around each change, old and new part one after the other -
-C NUM like -c with NUM lines of context -
--context[=NUM] like -c, with NUM lines of context -
-u unified format: 3 lines of context, removed lines with -, added lines with + -
-U NUM like -u with NUM lines of context -
--unified[=NUM] like -u, with NUM lines of context -
-r, --recursive compare directories down through all subdirectories -
-i, --ignore-case treat upper and lower case letters as equal -
-b, --ignore-space-change treat any run of spaces and tabs as one space, drop them at the line end -
-w, --ignore-all-space spaces and tabs do not count at all -
-a, --text compare files with zero bytes as text, too -
--help show this help and exit
44 more options of the real program, not in the simulator yet
-
-e, --ednot in the simulator yetOn a real system diff then writes commands for the ed editor.
-
-n, --rcsnot in the simulator yetOn a real system diff then shows the changes in RCS format.
-
-y, --side-by-sidenot in the simulator yetOn a real system diff then shows both files side by side in two columns.
-
-W, --widthneeds a value not in the simulator yetOn a real system it sets the width of the two columns of -y.
-
--left-columnnot in the simulator yetOn a real system with -y diff then shows equal lines only on the left.
-
--suppress-common-linesnot in the simulator yetOn a real system with -y diff then leaves out equal lines.
-
-p, --show-c-functionnot in the simulator yetOn a real system diff then names the C function a change is in.
-
-F, --show-function-lineneeds a value not in the simulator yetOn a real system diff then names the last line before a change that matches the pattern.
-
--labelneeds a value not in the simulator yetOn a real system LABEL then replaces the file name and time in the header of -u and -c.
-
-t, --expand-tabsnot in the simulator yetOn a real system diff then replaces tabs in its output with spaces.
-
-T, --initial-tabnot in the simulator yetOn a real system diff then puts a tab before the text of each line.
-
--tabsizeneeds a value not in the simulator yetOn a real system it sets how far a tab reaches.
-
--suppress-blank-emptynot in the simulator yetOn a real system diff then writes no space before empty lines.
-
-l, --paginatenot in the simulator yetOn a real system diff then splits its output into pages with pr.
-
--no-dereferencenot in the simulator yetOn a real system diff then compares symbolic links themselves, not their targets.
-
-N, --new-filenot in the simulator yetOn a real system a missing file then counts as empty.
-
--unidirectional-new-filenot in the simulator yetOn a real system a missing first file then counts as empty.
-
--ignore-file-name-casenot in the simulator yetOn a real system diff then ignores upper and lower case in names inside directories.
-
--no-ignore-file-name-casenot in the simulator yetOn a real system diff pays attention to upper and lower case in names (it does anyway).
-
-x, --excludeneeds a value not in the simulator yetOn a real system diff then skips files in directories whose name matches the pattern.
-
-X, --exclude-fromneeds a value not in the simulator yetOn a real system diff then reads the patterns for -x from a file.
-
-S, --starting-fileneeds a value not in the simulator yetOn a real system diff then starts at this file inside directories.
-
--from-fileneeds a value not in the simulator yetOn a real system diff then compares this file with every operand.
-
--to-fileneeds a value not in the simulator yetOn a real system diff then compares every operand with this file.
-
-E, --ignore-tab-expansionnot in the simulator yetOn a real system it then does not matter whether white space is tabs or spaces.
-
-Z, --ignore-trailing-spacenot in the simulator yetOn a real system white space at the end of a line then does not count.
-
-B, --ignore-blank-linesnot in the simulator yetOn a real system added or removed empty lines then do not count.
-
-I, --ignore-matching-linesneeds a value not in the simulator yetOn a real system changes whose lines all match the pattern then do not count.
-
--strip-trailing-crnot in the simulator yetOn a real system diff then removes a carriage return at the end of each line (files from Windows).
-
-D, --ifdefneeds a value not in the simulator yetOn a real system diff then writes both files as one, with #ifdef around the differences.
-
--old-group-formatneeds a value not in the simulator yetOn a real system it sets the format for groups of lines with -D.
-
--new-group-formatneeds a value not in the simulator yetOn a real system it sets the format for groups of lines with -D.
-
--unchanged-group-formatneeds a value not in the simulator yetOn a real system it sets the format for groups of lines with -D.
-
--changed-group-formatneeds a value not in the simulator yetOn a real system it sets the format for groups of lines with -D.
-
--line-formatneeds a value not in the simulator yetOn a real system it sets the format of each line with -D.
-
--old-line-formatneeds a value not in the simulator yetOn a real system it sets the format of one kind of lines with -D.
-
--new-line-formatneeds a value not in the simulator yetOn a real system it sets the format of one kind of lines with -D.
-
--unchanged-line-formatneeds a value not in the simulator yetOn a real system it sets the format of one kind of lines with -D.
-
-d, --minimalnot in the simulator yetOn a real system diff then searches longer for the smallest number of changes.
-
--horizon-linesneeds a value not in the simulator yetOn a real system it sets how many equal lines at the start and end diff looks at, too.
-
--speed-large-filesnot in the simulator yetOn a real system diff then works faster but less exactly on large files.
-
--colorvalue optional not in the simulator yetOn a real system diff then colors its output.
-
--paletteneeds a value not in the simulator yetOn a real system it sets the colors for --color.
-
-v, --versionnot in the simulator yetOn a real system diff then shows its version.
Examples
$ diff -u conf/app.conf.bak conf/app.conf
--- conf/app.conf.bak 2026-10-16 17:00:00.000000000 +0000
+++ conf/app.conf 2026-10-17 08:00:00.000000000 +0000
@@ -1,4 +1,4 @@
port = 8080
-workers = 2
-log_level = info
+workers = 4
+log_level = debug
timeout = 30 Where you learn it
Lessons
- Finding lines, finding differences Linux Basics, Module 3: Text tools