Last Updated: May 04, 2019
·
1.596K
· cwninja

Autocomplete last command's param

$ la /foo/bar/baz/bam/long-file-name
-bash: la: command not found
$ ls /foo/bar/baz/bam/long-file-name
Ahh, that't the one!

Is this as commoner part of your workflow as mine?

Rather than retyping the filename, or having to hit up arrow, go all the way to the left, and edit your last command, why not try typing ls then using <ESC>.?

It will insert the last param from the previous command, saving you over 14 years of typing over the course of a typical 1000 year life time.

<ESC>. (Escape dot), your flexible friend.

4 Responses
Add your response

Nice. You can also use $_ for this, as it is a short-hand for last command's parameter. Like this:

$ ls $_
over 1 year ago ·

I wonder how ESC + dot works in different Terminal implementations... I know that it works in the Mac Terminal but I wonder if this should be approached from the shell's perspective.

In which case $_ might be a better alternative to use.

over 1 year ago ·

For when you forget to run sudo on a command there's

sudo !!

And for another alternative

ls !$

where !$ is also the last "word" from the last command.

over 1 year ago ·

Alt+. also works, from my experience.

over 1 year ago ·