5 ms·
Alt + . does the same thing as well, with the added advantage that you can keep pressing alt and then hit . several times to go through all the "last arguments"
by alex_smart 6y ago
Alt + . does the same thing as well, with the added advantage that you can keep pressing alt and then hit . several times to go through all the "last arguments" in your history one by one.
Further, holding Alt followed by numeric argument followed by dot, gives you an argument at a specific position. For example, Alt + 1, Alt + . copies the first argument.
- seesawtron 6y agoCool one. "Ctrl + R" also does the same thing to search through past commands and then "Tab" to select the command you are looking for.
- alex_smart 6y agoMay favorite bash "trick" is: !-1:gs/hello/world which runs the last command with all instances of hello replaced by world. !-1 can be any so called event designator, for instance !n to refer to any specific line number from history or !string for last command containing a particular string. Seriously people, read the man page for bash. Your shell has so many cool features.
- tikkabhuna 6y agoAnd if you only have a single instance to replace, you can use ^old^new^ $ echo "hello hello hello world" hello hello hello world $ ^hello^bonjour^ echo "bonjour hello hello world" bonjour hello hello world
- alex_smart 6y agoI know that this expansion exists, but never use it in practice. Why? The last command is more general, you can just drop the g from the command I wrote to only replace the first occurrence. Besides, :[g]s/old/new should already be familiar to anyone who has used vim, so that is almost like having to learn zero new things.
- dcassett 6y agoThis is great for removing an option from a prior command such as unzip -t ...: ^-t
- rswail 6y agoTIL! Oh this one is nice... now just to get my fingers to remember it.
- pupdogg 6y ago[ESC + .] and [ALT + .] are most definitely news ones for me. Thank you. Always learn something new here!
- loulouxiv 6y agohttps://www.gnu.org/software/bash/manual/html_node/Bindable-Readline-Commands.html https://www.gnu.org/software/bash/manual/html_node/Bindable-... is a must read.
- alex_smart 6y agoThanks, I discovered C-o thanks to you (even though I have gone through the bash manual several times). No, more having to press C-r multiple times just to get sequential group of commands from history.
- loulouxiv 6y agoYes I was also impressed when I found out about this one. However I use it far less frequently than ALT-. . ALT-# is also useful in the frequent cases where I am constructing a complicated commmand but I have to run another command before the current one. Also keep in mind that most interactive command-line tools are built upon readline and can understand all those bindings (think python REPL, mysql/psql...)
- alex_smart 6y ago>However I use it far less frequently than ALT-. Haha of course. I use it so frequently I can't imagine how anyone uses their shell without it. >can understand all those bindings I knew that but just being reminded helped me realize that C-o is probably going to be useful in the REPL as well. Thanks.
- loulouxiv 6y agoor man bash /Readline Command Names<Enter>