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 frequently find myself doing something like the following:

$ big long command 1
$ big long command 2
$ diff -u <(big long command 1) <(big long command 2)

How can I get the shell (bash in my case) to construct that third command for me, without the need to cut and paste those big long commands into the <()s? (It's obviously fine if the big long commands are re-executed; they are assumed to be safe to re-run.)

share|improve this question
up vote 7 down vote accepted

You can use the Bash shell's history to get those last 2 run commands like so:

$ big long command 1
$ big long command 2
$ diff -u <(!-2) <(!-1)

This will take the current command minus 2 (big long command 1) and the current command minus 1 (big long command 2) and run them into diff.


share|improve this answer
also, you can pipe the output to diff if you wanted (although in this case may not have sense if you want to view the complete output before diffing): $ big long command 1; $ big long command 2 | diff -u <(!-1) - – Carlos Campderrós Jul 17 '13 at 22:38

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.