diff
Compare files line by line and show the differences between them.
Synopsis
diff [OPTION]... FILE1 FILE2
Examples
diff file1.txt file2.txt
diff -u old.conf new.conf
diff -r dir1/ dir2/
diff --color -u a.js b.js
Common options
| Flag | Description |
|---|---|
| -u | Unified diff format |
| -r | Recursively compare directories |
| -i | Ignore case differences |
| -w | Ignore all white space |
| --color | Colorize output |
About diff
The `diff` command compare files line by line and show the differences between them. Text viewing and editing commands are fundamental tools in any Linux user's toolkit.
Linux treats almost everything as a file, so the ability to quickly inspect, filter, transform, and edit file contents from the command line is critical. These commands are regularly combined with pipes and redirects to build powerful data-processing pipelines.
The command accepts 5 commonly used flags shown above, though the full set of options is available in the man page (`man diff`). The 4 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.
Related commands
More File Viewing & Editing Commands
Other commands in the File Viewing & Editing category