diff (short for difference) is a simple and easy to use tool which analyzes two files and displays the differences in the files by comparing the files line by line. It prints the lines that are different. Importantly, if you want the two files to be identical to each other, diff also outputs a set of useful instructions on how to change one file to make it identical to the second file.

 

To compare or find the difference between two files on different servers, run the following command. Remember to replace the user and remote host with your actual parameters.

$ ssh user@remote-host "cat /home/root/file_remote" | diff  - file_local

 

Note that you can also save the difference between the two files to a file, using the output redirection feature. For example:

$ ssh user@remote-host "cat /home/root/file_remote" | diff  -  file_local > diff_output.txt

 

Then use a cat command to view the contents of the diff_output.txt file.

$ cat diff_output.txt
OR
$ bcat diff_output.txt

 

In addition, you can also compare or find the difference between two files on two remote servers, as shown:

$ diff <(ssh user@remote-host1 'cat /path/to/file1') <(ssh user@remote-host2 'cat /path/to/file2')

 

For more information, consult the diff man page as shown.

$ man diff

Was this answer helpful? 0 Users Found This Useful (0 Votes)