web analytics

How to Compare the Contents of Local & Remote Files With the Help of SSH – Source: www.techrepublic.com

Rate this post

Source: www.techrepublic.com – Author: Jack Wallen


Image of Jack Wallen

on


How to Compare the Contents of Local & Remote Files With the Help of SSH

This is a step-by-step guide on how to compare the contents of local and remote files with the help of SSH. Watch the companion video tutorial by Jack Wallen.

Have you ever needed to compare the contents of a local and remote file without having to copy the remote file to the local machine and then run the diff command on both? Sure, it’s not exactly a challenging task, but it’s not exactly the most efficient way to compare those files.

What if I told you there was a way to do this without having to first copy that file from one machine to another? This ensures you don’t always have to first copy a fresh version of the file to get the most up-to-date content. We do this with the help of the three commands SSH, cat and diff, all of which should be installed on your Linux and macOS machines by default. Let me show you how it’s done.

Let’s say you have a file named test on both local and remote machines, and you want to compare the contents. To do this, open a terminal on one machine and enter the command

ssh user@host cat /path/to/file | diff /path/to/file -.

where user is a valid username on the remote machine, host is the IP address of the remote machine and /path/to/file is the explicit path to the file to be compared. After authenticating your remote account, diff will do its thing and print out the differences between the two files. And that’s all there is to it.

With this handy command, you can compare different files between local and remote machines without having to first copy the files to or from one machine to another. As always, it’s better to work smarter, not harder.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

Also See

Original Post URL: https://www.techrepublic.com/article/how-to-compare-local-remote-files-ssh/

Category & Tags: Apple,Developer,Networking,Open source,Security,linux,macos,network security,networking,remote machines – Apple,Developer,Networking,Open source,Security,linux,macos,network security,networking,remote machines

LinkedIn
Twitter
Facebook
WhatsApp
Email

advisor pick´S post

More Latest Published Posts