$ mkdir hi
$ cd <alt+.>
You can hit . several times to cycle through earlier final args. $ mkdir hi
$ cd <alt+.>
You can hit . several times to cycle through earlier final args.https://www.man7.org/linux/man-pages/man3/readline.3.html
All engineers working with the command line (even after 35 years) really, really should open and read
man bash
and man readlineto make sure you don't end up with something like urxvt-readline(1)
I would have referred to this using !$, which is one of the Bourne shell history substitutions. Like
$ mkdir awesome
$ cd !$
(The "!" has the connotation "history" in the shell, while the "$" has the connotation "last", as in regular expressions.)An advantage of the way you mentioned is that you could actually see the history item displayed on the command line before running the command!
sudo !!
for "run the entire previous command under sudo".Another example could be
echo "!!" > myscript
for "save the previous command into the file myscript".The generic form is !n:m for n-th last command line and m-th argument, with an omitted n being a shortcut for the last line.
Not sure if all of this works the same in bash.
There are several other ways to do this sort of thing too. See e.g. https://stackoverflow.com/questions/4009412/how-to-use-argum...
sudo !!
and cd -
takes you to the previous directory. $ grep blah *
$ ^r
(reverse-i-search)`g': grep blah *
This is far and above my most commonly used shell command