News for hackers. Stuff that matters.
Re:How to navigate directories faster with Bash (2015) by lolive on Thursday April 22, 2021 @03:18AM (#26899760)
Typing Esc then . does the trick too.
Re:How to navigate directories faster with Bash (2015) by alex_smart on Thursday April 22, 2021 @04:00AM (#26900075)
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.

Re:How to navigate directories faster with Bash (2015) by seesawtron on Thursday April 22, 2021 @04:39AM (#26900322)
Cool one. "Ctrl + R" also does the same thing to search through past commands and then "Tab" to select the command you are looking for.
Re:How to navigate directories faster with Bash (2015) by alex_smart on Thursday April 22, 2021 @05:10AM (#26900516)
May 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.

Re:How to navigate directories faster with Bash (2015) by tikkabhuna on Thursday April 22, 2021 @05:53AM (#26900774)
And 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

Re:How to navigate directories faster with Bash (2015) by alex_smart on Thursday April 22, 2021 @06:16AM (#26900981)
I 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.

Re:How to navigate directories faster with Bash (2015) by dcassett on Thursday April 22, 2021 @08:19AM (#26901876)
This is great for removing an option from a prior command such as unzip -t ...:

^-t

Re:How to navigate directories faster with Bash (2015) by pupdogg on Thursday April 22, 2021 @06:38AM (#26901164)
[ESC + .] and [ALT + .] are most definitely news ones for me. Thank you. Always learn something new here!
Re:How to navigate directories faster with Bash (2015) by loulouxiv on Thursday April 22, 2021 @09:00AM (#26902242)
Re:How to navigate directories faster with Bash (2015) by alex_smart on Thursday April 22, 2021 @12:29PM (#26904665)
Thanks, 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.

Re:How to navigate directories faster with Bash (2015) by loulouxiv on Thursday April 22, 2021 @06:41PM (#26909004)
Yes 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...)

Re:How to navigate directories faster with Bash (2015) by alex_smart on Thursday April 22, 2021 @08:27PM (#26909723)
>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.

Re:How to navigate directories faster with Bash (2015) by loulouxiv on Thursday April 22, 2021 @09:02AM (#26902255)
or man bash /Readline Command Names<Enter>
Re:How to navigate directories faster with Bash (2015) by rswail on Thursday April 22, 2021 @05:22AM (#26900588)
TIL! Oh this one is nice... now just to get my fingers to remember it.
Re:How to navigate directories faster with Bash (2015) by madacol on Thursday April 22, 2021 @04:39AM (#26900321)
Re:How to navigate directories faster with Bash (2015) by mraza007 on Thursday April 22, 2021 @04:56AM (#26900430)
I have been looking for this Thanks for sharing :)
Re:How to navigate directories faster with Bash (2015) by emmelaich on Thursday April 22, 2021 @08:33AM (#26901995)
Only in emacs editing mode.

Real programmers use set -o vi

Re:How to navigate directories faster with Bash (2015) by stjohnswarts on Thursday April 22, 2021 @05:06PM (#26908199)
I use that on test machines a lot and had put it in bashrc and heard some cussing from other devs so now I just have to type it every time I spend more than acouple seconds in a terminal :) .
Re:How to navigate directories faster with Bash (2015) by gadiyar on Thursday April 22, 2021 @03:39AM (#26899902)
I didn't know this. Really neat!
Re:How to navigate directories faster with Bash (2015) by itsmarsu on Thursday April 22, 2021 @03:51AM (#26899999)
That's just magical
Re:How to navigate directories faster with Bash (2015) by thomasahle on Thursday April 22, 2021 @03:55AM (#26900035)
How does that work?
Re:How to navigate directories faster with Bash (2015) by saagarjha on Thursday April 22, 2021 @04:09AM (#26900127)
M-. is readline's yank-last-arg binding.
Re:How to navigate directories faster with Bash (2015) by a3n on Thursday April 22, 2021 @06:36AM (#26901155)
Nice.

Bash is more than just bash. Composition is a killer technique.

Re:How to navigate directories faster with Bash (2015) by nmfisher on Thursday April 22, 2021 @04:11AM (#26900146)
You just blew my mind.
Re:How to navigate directories faster with Bash (2015) by teptoria on Thursday April 22, 2021 @03:49AM (#26899980)
Wow amazing! Thanks :)
Re:How to navigate directories faster with Bash (2015) by cerved on Thursday April 22, 2021 @03:25AM (#26899799)
what, what?