How do I diff files/folders across machines provided that the only connectivity available is ssh?

link|improve this question
There's a relatively similar question at #16661: How can I diff two RedHat Linux servers?. The answer there, to save the clicks, is rsync -ani --delete / root@remotehost:/ but the full answer gives more detail. – Owen Blacker Feb 14 at 18:30
feedback

8 Answers

You can do it with Bash's process substitution:

 diff foo <(ssh myServer 'cat foo')

Or, if both are on remote servers:

diff <(ssh myServer1 'cat foo') <(ssh myServer2 'cat foo')
link|improve this answer
2  
yeah, something like this, but for directories :) – Alexey Timanovsky Aug 26 '09 at 17:29
How do you mean for directories, could always replace cat with ls – Kyle Brandt Aug 26 '09 at 17:29
8  
I suspect that 'for directories' means doing a recursive diff – Ian Clelland Aug 26 '09 at 17:36
I found that this technique didn't work for me if my remote host required a password. The password prompt didn't seem to work well with the redirection and couldn't be successfully completed. If you use ssh keys this shouldn't be a problem. – Adam Franco Jan 24 at 14:28
feedback
up vote 14 down vote accepted

Finally I've found great solution: vimdiff

vimdiff /path/to/file scp://remotehost//path/to/file

thanks to http://linux.spiney.org/remote_diff_with_vim_and_ssh see also http://www.vim.org/scripts/script.php?script_id=1075 .

link|improve this answer
vimdiff is sweet, thanks! – Max Felker Oct 12 '11 at 19:32
feedback

If you just want to see what files are different, rather than a diff of the actual files, then you can use rsync --dry-run

link|improve this answer
1  
rsync -n is the short version. – Artem Shnayder Jan 3 at 23:48
feedback

Use scp to bring the files to a common machine and diff them there?

Or, if you just want to know if the files are different or not, hash them with md5sum on each machine.

You could also look into something like SSHFS, but I don't know how well an algorithm like diff performs over that.

link|improve this answer
2  
An easier way to see if the files are different or not is rsync --dry-run. – Gerald Combs Aug 26 '09 at 20:18
feedback

One way, if it is possible on your system would be to simply mount the remote filesystem with sshfs.

link|improve this answer
diff is usually one-shot action, like to check config difference. Mounting filesystem each time is possible, but not convinient. I'd better tar and scp. – Alexey Timanovsky Aug 26 '09 at 17:28
feedback

Here's another quick and dirty command line recipe:

ssh [login]@[host] "cat [remote file]" | diff - "[local file]"

link|improve this answer
feedback

Here is how I did it.

I used SFTP to the remote server and entered my username/pwd when prompted. Then I used the dir that was created in the .gvfs dir in my home directory in the diff command.

diff -r --brief /home/user dir/.gvfs/SFTP\ on\ freenas.local/path to dir/dir1 /path to local dir/dir2

link|improve this answer
feedback

This is a script that can help to diff local folder and remote folder.:

 #!/bin/bash

 LOCALFOLDER=/var/www/tee
 REMOTEFOLDER=$(ssh root@111.111.111.1 'ls -lA /hfs/tee'| grep -E '^total' | cut -d " " -f 2 > remotessh.txt)
 COMMAND=$(ls -lA $LOCALFOLDER | grep -E '^total' | cut -d " " -f 2 > localssh.txt)
 REM=$(cat remotessh.txt)
 LOCAL=$(cat localssh.txt)

 echo $LOCAL
 echo $REM

 if [ $REM -eq $LOCAL ]
 then
      echo Directories are the same
 else
      echo Directories are differnt
 fi

 #diff localssh.txt remotessh.txt | grep -E '^total' | cut -d " " -f 2
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.