I know that I can navigate through previous commands using the up & down arrow keys, making it easy to re-run an earlier line of code. However if I want to re-run multiple sequential commands I need to navigate back with the arrow keys for each line, which can get kind of cumbersome if I have entered many lines of code in between.

In Windows Command Prompt, one you have navigated back to a previous line of code & pressed enter to re-run it, you can simply press the down arrow key to get to the line which followed the original command. This makes it easy to run a sequence of commands from earlier in the session.

I know the Mac Terminal has lots of nice features & hotkeys so surely there must be some way to accomplish this?


If you run history, you will see a numbered list of previous commands. If you want, say, to run commands 123, 124, and 125 in sequence from your history, you can do this:

$ !123; !124; !125
  • This isn't exactly what I'm looking for, but it seems like it may be as close as I'm going to get. Thanks for the input. – corvus Sep 4 '18 at 22:57

Alternatively, if you're finding yourself running the same commands again and again, you might put them into a script:

$ echo "!123 && !124 && !125" > my_cool_script.sh
$ chmod +x my_cool_script.sh
$ ./my_cool_script.sh

Your Answer

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

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