More fun is available. Say you want to keep operating on a file (as above, where you're using test.py, repeatedly):
cp foo.py thing.py
- Copy an existing file to
- Edit (vim, emacs - though why you'd be using a command line if you were running Emacs-OS, I have no idea)
thing.py - the last word in the previous command line
History manipulation is such fun. Try
man history. Note that the quest to re-use history can result in typing far more than the command itself would. The final command substitution, where I replace thing.py by foo.py is one such example. Fewer characters to just type in the command and name. :)
The history substitution is also why you get strange messages when you try:
$ echo "This is a disaster!"
-bash: !": event not found
The exclamation mark is being consumed as a history reference, and it can't find a previous command with a double quote.