- How to Become a Chief Information Officer: CIO Cheat Sheet
- 3 handy upgrades in MacOS 15.1 - especially if AI isn't your thing (like me)
- Your Android device is vulnerable to attack and Google's fix is imminent
- Microsoft's Copilot AI is coming to your Office apps - whether you like it or not
- How to track US election results on your iPhone, iPad or Apple Watch
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.