I'm connected on a host via
ssh and I'd like to compare (let's say with
diff) a certain config file against its counterpart on an another host, also accessible via
ssh, without having to manually download the remote file first before running the diff.
ssh user@remote_host "cat remote_file.txt" | diff - local_file.txt
Maybe this is not helpful in your exact case, but I often simply use
on each machine, and manually compare the checksums. That allows for comparisons of files even when they are not reachable via an ssh connection. Of course, all it answers is "are they identical", but often that is sufficient for my needs. It also makes it easy to verify that a single file is the same on 3 or 4 or more machines.
If you'd prefer a more visual approach in you terminal session. The midnight commander has a remote file system option (SFTP link... option in the menu) and visual file compare option. It is not installed by default on most Linux systems but is available in most base repositories. Steps:
- Start midnight commander (command:
mc) in the folder containing the file to be compared
- On other side (for example the Right menu) create a sftp link to the other server at the same folder (
- Using the
inskey select/highlight the files to be compared. (
tabchanges between left and right panel).
- In the Command menu, select Compare files
Note: The midnight commander menu can usually be access using the mouse in your terminal session. It that doesn't work
F9 gets you in the menu also.