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?

link|improve this question

62% accept rate
feedback

4 Answers

up vote 10 down vote accepted

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

link|improve this answer
very cool, i'll give it a try – Phil Aug 26 '09 at 16:30
...i wonder how do i compare remote directory to local one? – Phil Aug 26 '09 at 16:43
1  
You would have to mount the remote directory to the local machine. However, you can remotely compare files like so: ssh REMOTE_SERVER "cat /path/to/some/file" | diff --side-by-side /path-to-some-file - One other thing, the 'sdiff' command works like 'diff --side-by-side' if you want to save some typing. – Sean Staats Aug 26 '09 at 18:13
it's high time to introduce version control on your files see svn, git (,maybe cvs). – asdmin Aug 26 '09 at 23:09
1  
Use NFS to mount the remote directory. On the remote server(server-b), edit /etc/exports and put the following in it: /path/of/directory/to/share server-a.ip.address(ro,no_root_squash) Start NFS on server-b (/etc/init.d/nfs start) Mount to your local server(server-a) by adding the following to /etc/fstab: server-b.ip.add:/path/of/directory/to/share /mnt/server-b nfs rsize=32768,wsize=32768,rw 0 0 Then on server-a, mkdir /mnt/server-b; mount /mnt/server-b Thanks for the upvotes. – Sean Staats Aug 27 '09 at 12:40
show 3 more comments
feedback

AIDE Advanced Intrusion Detection Environment (AIDE) is a file integrity checker for UNIX operating systems. Its purpose to provide reporting on the integrity of data on supported file systems. By running AIDE multiple times on the target host you can determine what files are changing. By running AIDE multiple times on different hosts you can determine what files and permissions are different. Then use a gui diff tool on the reported "different" files.

Or use a gui diff tool like meld, guiffy, kdiff3, diff, vimdiff, gvimdiff, Emacs, Kompare, Diffuse, Easydiff, TkDiff or xxdiff. Most will do directory diffs in addition to file diffs. You'll need to mount the remote drive using NFS, SMBFS or SSHFS as others have mentioned.

link|improve this answer
feedback

Assuming:

  • we are on www1, comparing with remote www2
  • there is public Key authentication from local www1 to remote www2
  • we compare as the same user on local www1 and remote www2
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 
link|improve this answer
feedback

Or you can use two files with the out put of list of files. And then compare those two files. For example:

/path/to/compare/remote$: ls > remote-files 

/path/to/compare/local$: ls > local-files 

Download one of the files.

-rw-r--r-- 1 1015 1015    26624 2005-06-14 13:10 FILE.TXT  

to FILE.TXT

Use diff (diff -y remote-files local-files > diff-files) to compare them side by side. Open the diff-files and check it. Each line with > means a different file.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.