The magic works in two parts.
First, echo is aliased to e (echo will work also if you want no alias); second, we use "brace expansion":
$ e mv {,_}test_1.py # Try to see if it works as expected.
mv test_1.py _test_1.py
# If the arguments are what you want:
$ mv {,_}test_1.py # Press ↑ (up arrow), remove `e`
$ !* # OR: Type `!*` --> last line after arg 0.
$ mv {,_}test_1.py # If `histverify` is set.
The !* may be expanded with an space if you enable magic-space or if you set shopt -s histverify
after you press enter, you will be given a chance to review the effect of the history expansion before pressing enter (again) to execute.
The other example:
$ e mv test_1.py{,.org}
mv test_1.py test_1.py.org # The result of the brace expansion.
# Review it, and if it is ok:
$ !* # type !* (use either space or enter)
# That will depend on how you setup it.
$ mv test_1.py{,.org} # The command appear again (enter to execute).
$
There is also the history expansion of !#
which means the command line typed so far, and selecting the first command :1
. If you have magic-space enabled, you type mv test1.py !#:1
and press space, the command will change:
$ mv test_1.py !#:1 # Press space.
$ mv test_1.py test_1.py # The command line change to this.
$ mv test_1.py test_1.org # Edit and press enter to execute.
mv {,_}test_1.py
– Jeff Schaller Dec 17 '16 at 13:36man bash
. Search!!
– waltinator Dec 17 '16 at 16:19!#$
answer, which I somehow missed, and which is what I was looking for. Sometimes it's right under your nose and you miss it. – boardrider Dec 17 '16 at 20:54