Quick Tip
Someone asks "what's different between these two folders?" and people reach for a GUI tool or start writing a Python script. diff already does it:
diff -rq dirA/ dirB/
Output is exactly what you want — nothing else:
Only in dirA/: config.local.yml
Files dirA/app.py and dirB/app.py differ
Only in dirB/logs: error.log
Three lines tell you: one file only exists locally, app.py has drifted, and there's a stray log on the other side.
The flags that matter:
| Flag | What it does |
|---|---|
-r |
Recurse into subdirectories |
-q |
Report only whether files differ, not the diff itself |
--brief |
Same as -q (GNU) |
-x PATTERN |
Exclude files (e.g. -x '*.pyc' -x '__pycache__') |
Real use case from last week — verifying a deploy actually copied everything:
diff -rq --exclude='.git' --exclude='node_modules' \
./build/ /var/www/app/
# no output = byte-identical trees = deploy was clean
Want the actual differences for just the files that drifted? Pipe it:
diff -rq dirA/ dirB/ | grep '^Files' | cut -d' ' -f2 | \
xargs -I{} sh -c 'echo "=== {} ==="; diff {} $(echo {} | sed s/dirA/dirB/)'
Works on every Linux/macOS box you'll ever SSH into. Zero installs, zero network, zero excuses.
Powered by MonkeyCode — free AI coding assistant: https://ly.cyberserval.tech/iIETXiF
Top comments (0)