Compare files line by line and show differences.
low risk
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.
| Flag | Meaning |
|---|---|
-u --unified | Unified diff format (standard for patches) |
-r --recursive | Compare directories recursively |
-i --ignore-case | Ignore case differences |
-w --ignore-all-space | Ignore all whitespace differences |
-q --brief | Report only whether files differ |
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 →Use `diff <(command1) <(command2)` with process substitution to compare command outputs without creating temp files — works for comparing live config with desired state.
Reference text is hand-written and may be incomplete — check man diff for your version. Test destructive commands on a non-production system first.