Saturday, April 26, 2008
4:34 AM

Fast way to execute sequential commands from the command history

When I had to navigate to a subdirectory in a deep hierarchy, I found myself do a lot of cd's.
$ cd /home/peter
$ cd level1
$ cd level2
$ cd level3
$ cd level4
$ pwd
/home/peter/level1/level2/level3/level4

If I ever need to revisit that level4 subdirectory, re-running those same commands in the same order from the command history can be a real chore. You have to keep finding your way back in history to execute the next command.

bash has a short cut, Cntl-O (as in Control-Oh), that is your friend here.

Simply go back to the first command in the series (cd /home/peter).
Hit Cntrl-O (instead of Enter), and it will run that command, and automatically display the next command for you (cd level1).

You can do one of several things at this point:

  • You can hit Cntl-O to run the currently displayed command, and display the next one (cd level2).
  • You can hit Enter to run the current command, and terminate the sequence (next command is NOT displayed).
  • You can hit Cntrl-C, and the current command is NOT executed, and the next command is NOT displayed.


Cntl-O can be a real time saver.
StumbleUpon Toolbar

0 comments:

Post a Comment