Quickly compare files and directories to pinpoint added, removed, or modified lines. 06.03.2026 | reading time: 2 min When a configuration breaks or two source files diverge, run diff to see exactly which lines were added, removed, or changed and why. A hands-on comparison Create two small files and compare them to see the unified diff output: ```bash echo "alpha" > a.txt echo "beta" >> a.txt echo "alpha" > b.txt echo "beta changed" >> b.txt diff -u a.txt b.txt ``` The expected unified diff output looks like this: ```diff --- a.txt +++ b.txt @@ -1,2 +1,2 @@ alpha -beta +beta changed ``` Options that matter Use `-u` for unified format suitable for patches, `-c` for context, `-r` to recurse directories, `-i` to ignore case, `-w` to ignore all whitespace and `--brief` to report only whether files differ; check exit codes 0 for identical, 1 for differences, 2 for errors. Where diff fits in workflows Generate a unified diff and pipe it to `patch` to apply changes, inspect changes before committing to version control, or combine with `rsync` and scripting to automate deployments and backups. Next steps and learning Practice comparing source trees, produce a patch with `diff -ruN` and apply it with `patch -p1`, then explore how version control systems present diffs; to deepen Linux skills consider exam preparation like CompTIA Linux+ or LPIC-1 with intensive courses at bitsandbytes.academy. Join Bits & Bytes Academy First class LINUX exam preparation. utilities version-control scripting troubleshooting