Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I wanted to be clever and compare a remote file to a local file without downloading it. I can get the contents of the remote file by

ssh user@remote-host "cat path/file.name"

However, piping that to diff

ssh user@remote-host "cat path/file.name" | diff path/file.name

gives me this:

diff: missing operand after `path/file.nae'
diff: Try `diff --help' for more information.

I have ssh keys set up, so it's not prompting me for a password. What's a workaround for this?

share|improve this question
5  
By the way, you're still downloading the file when you do this (since its content gets sent over the SSH connection), you're just not saving it anywhere. So it's not like you save any bandwidth or anything. –  David Z Aug 21 '10 at 0:13
1  
Yeah, I just don't want to muck up my file system with one-shot files hanging around. –  user394 Aug 23 '10 at 13:29

4 Answers 4

up vote 28 down vote accepted

Try to use - to represent the standard input.

ssh user@remote-host "cat path/file.name" | diff path/file.name -

share|improve this answer

Here's one workaround: diff seems to accept <(expr) as arguemnts:

diff <(ssh \"cat path/file.name/") <(cat path/file.name)
share|improve this answer
7  
That's not diff, that's the shell (bash, ksh and zsh support this syntax, but it's not POSIX), with some help from the kernel (it must provide /dev/fd: diff sees something like /dev/fd/3 on its command line). –  Gilles Aug 20 '10 at 19:25
1  
It doesn't "must provide" - shells can create temporary named pipes for this feature too. –  ephemient Sep 24 '10 at 14:11
1  
this is the coolest answer! –  neves Dec 20 '11 at 21:47
    
This is what I needed, thanks. :) –  Anders Holmström May 13 at 6:12

Piping into diff is equivalent to running

diff path/file.name

and then, once it's running, typing the entire contents of the file.

As you can see, that's not what you expected.

share|improve this answer
    
No workaround? :( –  user394 Aug 20 '10 at 18:56
    
Look at Hemant's answer. I didn't know of one. –  Macha Aug 20 '10 at 18:59
diff /tmp/localtempfile <(ssh -A -o StrictHostKeyChecking=no root@server "cat /tmp/remotetempfile")
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.