$ run as a normal user# run as root (or with sudo)
The quick answer
diff -u nginx.conf.bak nginx.conf
diff -rq /etc/nginx /tmp/nginx-old
sha256sum backup.tar.gz /mnt/copy/backup.tar.gz
diff <(ssh web1 cat /etc/nginx/nginx.conf) <(ssh web2 cat /etc/nginx/nginx.conf)Step by step
- Text files — the unified diff:
diff -u nginx.conf.bak nginx.conf
--- nginx.conf.bak 2026-11-18 09:10:00
+++ nginx.conf 2026-11-19 10:02:41
@@ -12,7 +12,7 @@
keepalive_timeout 65;
- client_max_body_size 1m;
+ client_max_body_size 50m;- = only in the first file, + = only in the second, @@ = the line numbers. Add --color for colour; -w ignores whitespace changes.
- Folders:
diff -rq /etc/nginx /tmp/nginx-old
Files /etc/nginx/nginx.conf and /tmp/nginx-old/nginx.conf differ
Only in /etc/nginx/conf.d: shop.conf
diff -ru /etc/nginx /tmp/nginx-old > nginx-changes.diff-q = only the names; -u = the full changes of every file.
- Binary files and copies — compare checksums (exact, fast, works for any size):
sha256sum backup.tar.gz /mnt/copy/backup.tar.gz
cmp -s file1.bin file2.bin && echo same || echo different- Big folder trees (millions of files) — let rsync compare by checksum without copying:
No output = the trees are equal.
- Two servers, without copying files — process substitution
<( … ):
diff -u <(ssh web1 cat /etc/nginx/nginx.conf) <(ssh web2 cat /etc/nginx/nginx.conf)
diff <(ssh web1 rpm -qa | sort) <(ssh web2 rpm -qa | sort)The second line shows which packages differ between the two servers.
- Changes of config files over time: keep
/etcin Git (etckeeper) or compare with the package original:
rpm -V nginx
S.5....T. c /etc/nginx/nginx.conf5 = content changed, c = config file. On Debian/Ubuntu: dpkg --verify nginx.
- Sorted lists (users, packages, IPs) —
commshows only-in-A, only-in-B and both:
comm -3 <(sort list-a.txt) <(sort list-b.txt)Check that it worked
You can name every difference — or prove there is none: diff prints nothing and returns exit code 0, checksums match, and the rsync dry run lists nothing.
diff -q a.conf b.conf && echo "identical"Common problems
| Problem | Cause | Fix |
|---|---|---|
| Every line is different | Windows line endings (\r\n) or different indentation. | diff --strip-trailing-cr, -w; convert with dos2unix. |
Binary files … differ | Not text. | Use checksums or cmp; for archives compare the file list. |
diff -r is very slow | Huge trees. | rsync -rcn -i or compare checksum lists. |
| The diff of two servers shows only order changes | Lists not sorted. | sort both sides first. |
ssh asks for a password twice | No key login. | Set up SSH keys first. |
Same content, diff says different | Hidden whitespace or encoding (UTF-8 BOM). | cat -A to see hidden characters. |
Go further
- Command pages: sort, ssh, rsync, git.
- Next how-tos: Sync folders with rsync, Copy files between servers, Resolve a Git merge conflict.
- Learn it: TLCL — Compare text, TLCL — patch, TLCL — Process substitution.
1In a unified diff, what do lines starting with - and + mean?
- is only in the first (old) file, + only in the second (new) file.
2How do you compare one config file on two servers without copying it?
diff <(ssh web1 cat FILE) <(ssh web2 cat FILE).