How to Compare Local/Remote Directory Differences in Linux: File Diff Tools and Revision Visualization Techniques


1 views

The most straightforward way to compare two directories is using the diff command:

diff -qr /path/to/old_backup /path/to/new_backup

Key flags:

  • -q: Only report when files differ
  • -r: Recursive comparison
  • -u: Unified diff format (more readable)

For side-by-side comparison with highlighting, use these tools:

vimdiff

vimdiff old_backup/file.txt new_backup/file.txt

meld (GUI tool)

meld /path/to/old_backup /path/to/new_backup

To focus on text/php files only:

diff -r --unified --color \
  --from-file=/old_backup \
  $(find /new_backup -type f $-name "*.txt" -o -name "*.php"$)

For comparing local with remote directories:

Using rsync (dry run)

rsync -n -avic --dry-run user@remote:/remote/path/ /local/path/

SSH + diff combo

diff -r <(ssh user@remote "find /remote/path -type f -exec cat {} +") \
       <(find /local/path -type f -exec cat {} +)

For complete revision history visualization:

  • git: Initialize a repo and use git diff
  • rdfind: Find duplicate/unique files
  • diffoscope: Advanced comparison tool

Generate HTML diff output:

diff -u old.php new.php | \
  aha --black --title "PHP File Differences" > diff.html

Open diff.html in browser for colored, side-by-side comparison.


For directory comparison in Linux, the diff command is your primary weapon. The basic syntax for comparing two local directories is:

diff -qr /path/to/old_backup /path/to/new_backup

Key flags:
-q reports only when files differ
-r enables recursive directory comparison
-u produces unified output with context

For PHP and text files where you want Wikipedia-style side-by-side comparison with highlighting:

diff -y --color /old/file.php /new/file.php

Alternatively, use vimdiff for an interactive experience:

vimdiff old/file.txt new/file.txt

To see detailed changes within specific file types (PHP/text):

for file in $(diff -qr old/ new/ | grep -E '\.php$|\.txt$' | awk '{print $4}'); do
    echo "==== Changes in $file ===="
    diff -u "old/$file" "new/$file" | colordiff
done

To compare a remote directory with your local one, use SSH combined with process substitution:

diff -qr local_dir/ <(ssh user@remote "cd remote_dir; find . -type f -exec cat {} \;)")

For more efficient remote comparison, consider rsync in dry-run mode:

rsync -nrc --out-format="%f" local_dir/ user@remote:remote_dir/

If you have Git available, it provides excellent diff visualization:

git diff --no-index old_dir/ new_dir/

For colored, word-level diffs:

git diff --no-index --color-words old_dir/file new_dir/file

For those preferring graphical tools:

  • meld - Excellent graphical diff tool
  • kompare - KDE's diff application
  • diffuse - Python-based GUI diff tool

Install with:

sudo apt install meld  # Debian/Ubuntu
sudo dnf install meld  # Fedora

Create a bash script for periodic directory snapshots:

#!/bin/bash
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
diff -rq original/ modified/ > "changes_$TIMESTAMP.log"
grep -r -n -i --color "changed_pattern" modified/ >> "changes_$TIMESTAMP.log"