How to Have the Last Word (on the command-line)

December 12, 2014

Have you ever done this?

% mkdir some_dir
% cd some_dir

Did you type some_dir twice? Here’s the same task, done in 3 different ways.

Worst: doing it manually

doing it manually

This is the looooong way. I’m typing everything and pretending I’m on a typewriter.

Better: using the history

using the history

I’m using !$ (the last word from the previous command) instead of typing it out. Better still, I’m using ‘magic-space’ to do automatic history expansion and check what I’m going to get.

More on “magic-space” on this page, scroll to slide 15.

Best: using ESC-.

using esc-dot

How did the directory’s name just appear? There is a keyboard shortcut for that and it’s already configured on your terminal: type ESC followed by the period (ESC-.).

(It also works as META-. or ALT-.)

If you keep pressing ESC-., it will traverse the history backward and insert the last word from previous commands.


There are a lot of commands that take a “target” as their last argument:

It’s not uncommon to chain multiple of these commands on the same “target”. You just created directory, you might very well want to step into it.

Let the command-line help.

Discuss on Twitter