How to Have the Last Word (on the command-line)
Have you ever done this?
Did you type
some_dir twice? Here’s the same task, done in 3 different ways.
Worst: doing it manually
This is the looooong way. I’m typing everything and pretending I’m on a typewriter.
Better: using the history
!$ (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-.
How did the directory’s name just appear? There is a keyboard shortcut for that
and it’s already configured on your terminal: just type
ESC followed by the
(It also works as
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:
- cp / mv / rm
- rmdir / mkdir
- cat / touch
- (any text editor)
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.