DEV Community

Alex Chen
Alex Chen

Posted on

Quick Tip: Diff Two Directories and Get a Clean Summary with `diff -qr` (No GUI Needed)

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/
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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/)'
Enter fullscreen mode Exit fullscreen mode

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

coding #tips #linux #productivity

Top comments (0)