commands

diff — compare text files

Reports differences. -u selects unified format. Exit 0 identical, 1 different, 2 trouble. Read-only for regular file comparison; output is not itself an applied change. Example assumes a fresh search-transform lab fixture.

Formal Syntax & Structure

linux syntaxlinux
diff [OPTION]... FILE1 FILE2

Parameters & Attributes

NameTypeDescription
-uoptionunified format
FILE1operandold input
FILE2operandnew input

Return Value

exit status and output

Reports differences. -u selects unified format. Exit 0 identical, 1 different, 2 trouble. Read-only for regular file comparison; output is not itself an applied change.

Working Example

Example Snippetlinux
rc=0diff -u --label old.txt --label new.txt old.txt new.txt || rc=$?printf "status=%s\n" "$rc"test "$rc" -eq 1
Linux Reference