Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
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
up vote 45 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
when comparing giant files (such as linux disk images) this is outputting them all to the console! even with diff -s (for "same") it does this. – user391339 Oct 20 '14 at 1:53

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
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
It doesn't "must provide" - shells can create temporary named pipes for this feature too. – ephemient Sep 24 '10 at 14:11
this is the coolest answer! – neves Dec 20 '11 at 21:47
This is what I needed, thanks. :) – Anders Holmström May 13 '14 at 6:12
I personally prefer this answer. I needed to diff two different XML files; but they needed to be properly formed first. That led to this: diff -y <(xmllint --format "${1}") <(xmllint --format "${2}") which I now use all the time. – BCqrstoO Oct 8 '14 at 19:49

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


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.