Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Lets say my last 3 commands were: % rm foo.out % myprog > foo.out % cat foo.out

I will like to invoke the last 3 with one stroke of the enter key, i.e. do some shell history commands which invke: % rm foo.out && myprog > foo.out && cat foo.out

How can I do this?

share|improve this question
up vote 6 down vote accepted

History expansion works pretty similarly in bash and zsh, use !-N to reference the Nth previous command

$ echo foo
$ echo bar
$ echo baz
$ !-3 && !-2 && !-1
echo foo && echo bar && echo baz
share|improve this answer
+1. If you want to execute all 3 commands regardless of their exit statuses, use ; instead of && – glenn jackman Mar 30 '12 at 0:57

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.