Diff command to compare files on different servers--Unix

44,311

Solution 1

You can copy the file over from the other server using scp and then use diff.

Or ssh to the remote host and diff using a single command like this:

ssh user@remote "cat /path/to/remote/file" | diff - /path/to/local/file

Solution 2

If your comparing multiple files, then look up rsync and rdiff, which save you the bandwidth of copying all files.

Btw, if your files are very large, then please update your question with that information.

Solution 3

I know it's a late answer but I take the question literally, no local file and two remote files.
In bash (and not only) it's possible to use the process substitution [1,2] <(...):

diff <(ssh Server1 'cat /path/to/file1') <(ssh Server2 'cat /path/to/file2')

The process <(list) is run asynchronously, and its input or output appears as a filename.

Note

  • Of course if you need only one remote file you can put the local file instead one of the <(...).
  • If both files are on the same server you can use a simpler

    ssh Server1 'diff /path/to/file1 /path/to/file2'
    

Solution 4

The "-" diffs against STDIN. You can do something like this:

ssh server 'cat file_to_diff' | diff -u localfile -
Share:
44,311
Anusha Pachunuri
Author by

Anusha Pachunuri

Updated on July 05, 2022

Comments

  • Anusha Pachunuri
    Anusha Pachunuri almost 2 years

    Can I use the diff command to compare files on two different servers? If not, is there any other option?