In my
last post, I demonstrated how you can use the !! and !$ features of your Bash & zsh history to get your work done more quickly. I use the former all the time, but the latter? Well, not so much. This is because I use something even better for
interactive shell use. It is M-. That is Meta plus period. All you Emacs
zealots users will know what I mean by
Meta. :) The
Meta-key is Alt on your computer, or sometimes Esc. Both work on my machine, but I prefer Alt over Esc, because it is less work.
Try doing M-. in your shell (Press and hold the Alt key, and then press the period key). Like !$, M-. will give you the last part of the last command entered, but this time
you can see it immediately. Better still, you can cycle through all of your commands. Just keep hitting M-. and the shell will display the last part of each command, in order, from newest to oldest.
Note: If you use the ESC key for your 'Meta' key, then you need to release the ESC key each time. Otherwise, if you hold it down and tap the . (period) key, it will return the end of the last command only once, and then start echoing the period after it.
As an example, say you had just finished a
grep fred /etc/passwd
You are ready to use the command line history feature:
vi M-.
Which would expand to (immediately):
vi /etc/passwd
Then, if it looks right, just press Enter.