Using 'diff' command over ssh

If I have a folder with several files on my computer, and a copy of the same folder on a remote server, is it possible to run 'diff' through ssh so I can see the differences between my copy and the one on the remote server? Ideally, I'd like to see if there are any additional/less files in either copy of the folder and then check to see if the individual files themselves have any differences.

3 Answers

To see if there are any additional/less files in either copy of the folder

diff -y <(ssh user@remote_server 'ls -1aR /remote_folder/') <(ls -1aR /local_folder/)

diff only works with local files. You might use scp or rsync to copy the files to a local directory and compare it with diff, or you can use something like sshfs to mount a remote directory to a local one and compare it with the second one.

For a single file, you can use ssh and diff:

ssh user@machine cat remote-file | diff - local.file
1

An alternative to find which files differ is to use rsync, as described in . Use

rsync -anicu . user@remote_host:directory/

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like