The diff command line utility compares contents of two files (or directories), and shows how they differ line by line. It's straightforward to use
The diff utility can take one operand in the form of stdin (represented by "-"), and you can leverage this feature to diff over SSH as follows.
The above command line will prompt you for an SSH password to the remote host. Once you enter the password correctly, the command will read the content of a remote file via SSH, and then pipe it into diff utility for comparison with a local file.
Another method for doing diff over SSH is to use input redirection explicitly. In order to use this second method, you need to first enable password-less ssh login to remote host(s). Assuming that is the case, you can do the following.
To diff a local file and a remote file:
To diff two remote files:
Note that the above commands will fail if the remote hosts require you to enter an SSH password for access. Also note that the above input direction is not supported by sh shell. Use bash shell or something compatible.
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!