How to compare differences between directories (linux)
I have two directories - one from earlier backup and second from newest backup. How do i compare what changes were made to files in directory from newest backup on Linux? Also how do i display changes in for example text and php files - i'm thinking about something like revision history on wikipedia where you see old version on one side of the screen and newest version on other and changes are highlighted. How do i achieve something like that?
edit: How do i also compare remote dir with local?
Solution 1:
From diff man page:
If both from-file and to-file are directories, diff compares corresponding files in both directories, in alphabetical order; this comparison is not recursive unless the -r or --recursive option is given. diff never compares the actual contents of a directory as if it were a file. The file that is fully specified may not be standard input, because standard input is nameless and the notion of ‘‘file with the same name’’ does not apply.
So to compare directories: diff --brief -r dir1 dir2
To compare files side by side: diff --side-by-side file1 file2
Solution 2:
You really want to combine the power of rsync
to reduce bandwidth consumption with the power of diff
to give you flexible, well um diffs.
So something like this:
cp -R $local $bak
rsync $server:$remdir/* $local/
rsync $local/ $server:$remdir/*
diff -wur $local $bak
I guess you could tweak this a bit if you were doing it often use rsync
instead of cp
in the first line - obviously in the last line you have the full power of diff
to format it however you like. Probably with y in the OPs case
Downside of this approach is you end up using twice as much local space, but at less than $1/gig who cares?
Solution 3:
Assuming:
- we are on
www1
, comparing with remotewww2
- there is configured public ssh key authentication from local
www1
to remotewww2
- we compare as the same user on local
www1
and remotewww2
find /var/www/html/ -name "*" -exec md5sum -b {} \; | grep -v "/var/www/html/exclude_this dir" > local.md5 ssh www2 "find /var/www/html/ -name '*' -exec md5sum -b {} \; | grep -v /var/www/html/exclude_this dir > remote.md5" scp www2:remote.md5 . diff local.md5 remote.md5