diff

Compare files line by line and show differences.

low risk

interactive breakdown — edit the command and press Explain
$ 
What it does

diff compares two files and outputs the differences in a format that can be applied as a patch. The -u flag produces unified diff format (the standard for patches and code review). Useful for config auditing, reviewing changes before applying, and generating patches.

Common flags
FlagMeaning
-u --unifiedUnified diff format (standard for patches)
-r --recursiveCompare directories recursively
-i --ignore-caseIgnore case differences
-w --ignore-all-spaceIgnore all whitespace differences
-q --briefReport only whether files differ
Examples
diff -u config.yaml.bak config.yamlShow changes since backup in patch format · explain & risk-check →
diff -r /etc/nginx.bak /etc/nginxCompare nginx config directories · explain & risk-check →
diff <(kubectl get cm myconfig -o yaml) config.yamlCompare live ConfigMap with local file · explain & risk-check →
diff -q dir1 dir2Quick check if directories differ · explain & risk-check →
Pro tip

Use `diff <(command1) <(command2)` with process substitution to compare command outputs without creating temp files — works for comparing live config with desired state.

Related
git log patch sed
Open the full explainer →More in Text Processing

Reference text is hand-written and may be incomplete — check man diff for your version. Test destructive commands on a non-production system first.