Text and processing

The diff command

Compares two files line by line and shows the differences. It is the basis of patches and version control.

Syntax

diff archivo1 archivo2

Most useful options

-uUnified format, easier to read
-iIgnores case

Copy-ready examples

$ printf 'a\n' > uno.txt && diff uno.txt uno.txtCompare (no output if equal)

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • diff prints nothing when the files are identical; silence is good news.
  • It returns a non-zero exit code if there are differences.

Related commands

FAQ

How does it differ from cmp?

diff compares line by line; cmp compares byte by byte.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course